{
  "version": "3.16",
  "name": "IncrementalUpdate",
  "sectionMerge": true,
  "registry": {
    "params": [
      "changeRequest(STRING)",
      "currentMeta(OBJECT)"
    ],
    "services": [],
    "apis": [],
    "components": [],
    "vars": [
      "$updatedMeta(OBJECT)",
      "$metaDiff(OBJECT)",
      "$affectedFiles(OBJECT)",
      "$regeneratedFiles(OBJECT)"
    ],
    "files": {
      "inputs": [
        ".vl-code/ProjectMeta.json"
      ],
      "artifacts": [
        "Services/*",
        "Sections/*",
        "ExtComponents/*",
        "Apps/*"
      ]
    },
    "docs": {
      "1": "VL Syntax Rules"
    }
  },
  "steps": [
    {
      "id": "LLM_010_AnalyzeMeta",
      "meta": {
        "title": "Analyze current metadata + change request"
      },
      "in": {
        "docs": [
          "1"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Current ProjectMeta:"
          },
          {
            "role": "user",
            "content": "=currentMeta"
          },
          {
            "role": "user",
            "content": "Change Request:"
          },
          {
            "role": "user",
            "content": "=changeRequest"
          },
          {
            "role": "user",
            "content": "Return ONLY the FULL updated ProjectMeta JSON. Preserve specVersion, projectName, vlVersion, config, every existing filePath, and every unaffected app/section/component/service/database entry. Apply only the requested change and keep the result internally consistent."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_object"
          }
        }
      },
      "out": {
        "$updatedMeta": "=_result"
      },
      "next": "MetaDiff_020_DiffMeta"
    },
    {
      "id": "MetaDiff_020_DiffMeta",
      "meta": {
        "title": "Compute metadata diff (deterministic, no LLM)"
      },
      "in": {
        "oldMeta": "=currentMeta",
        "newMeta": "=$updatedMeta"
      },
      "out": {
        "$metaDiff": "=_result",
        "$affectedFiles": "=_result.affectedFiles",
        "/.vl-code/ProjectMeta.json": "=$updatedMeta"
      },
      "next": "Loop_RegenFiles"
    },
    {
      "id": "Loop_RegenFiles",
      "meta": {
        "title": "Regenerate affected VL files"
      },
      "source": "=$affectedFiles",
      "mode": "parallel",
      "children": [
        "LLM_030_RegenFile"
      ],
      "next": "Set_040_SkipValidation",
      "onError": "skip"
    },
    {
      "id": "LLM_030_RegenFile",
      "meta": {
        "title": "Regenerate single VL file"
      },
      "in": {
        "docs": [
          "1"
        ],
        "stream": true,
        "max_tokens": 32768,
        "readFiles": [
          "=_item"
        ],
        "messages": [
          {
            "role": "user",
            "content": "File to regenerate:"
          },
          {
            "role": "user",
            "content": "=_item"
          },
          {
            "role": "user",
            "content": "Updated metadata:"
          },
          {
            "role": "user",
            "content": "=$updatedMeta"
          },
          {
            "role": "user",
            "content": "Change context (diff):"
          },
          {
            "role": "user",
            "content": "=$metaDiff"
          },
          {
            "role": "user",
            "content": "Regenerate the COMPLETE file at this path using the updated metadata and diff context. Preserve unaffected behavior and structure, and output ONLY the updated file contents. For VL source files (.vs/.cp/.sc/.vx), the first non-empty line MUST be '// VL_VERSION:3.7'."
          }
        ]
      },
      "out": {
        "/{_item}": "=_result"
      },
      "onError": "retry",
      "retryCount": 1,
      "next": "RETURN"
    },
    {
      "id": "Set_040_SkipValidation",
      "meta": {
        "title": "Skip validation (generation-only mode)"
      },
      "target": "$validationSkipped",
      "value": "=true",
      "next": "Stop_Done"
    },
    {
      "id": "Stop_Done",
      "meta": {
        "title": "Incremental update complete"
      }
    }
  ]
}
