{
  "version": "3.16",
  "name": "VL_FullStack_CodeGen_6Files",
  "description": "Full-stack code generation for medium-large projects using 6 auxiliary files, default Theme/Theme.vth, and fully parallel VL file generation.",
  "registry": {
    "params": [
      "userRequest(STRING)",
      "targetLang(STRING)"
    ],
    "services": [],
    "apis": [],
    "components": [],
    "vars": [
      "$blueprint(OBJECT)",
      "$blueprintStr(STRING)",
      "$dataSchema(OBJECT)",
      "$dataSchemaStr(STRING)",
      "$layoutPlan(OBJECT)",
      "$layoutPlanStr(STRING)",
      "$fileManifest(OBJECT)",
      "$fileManifestStr(STRING)",
      "$contractSheet(OBJECT)",
      "$contractSheetStr(STRING)",
      "$stateBehavior(OBJECT)",
      "$stateBehaviorStr(STRING)",
      "$vdbCode(STRING)",
      "$vthCode(STRING)",
      "$specValidation(OBJECT)",
      "$codeValidation(OBJECT)",
      "$repairPlan(OBJECT)"
    ],
    "files": {
      "inputs": [],
      "artifacts": [
        "Process/Specs/*",
        "Database/*",
        "Theme/*",
        "Services/*",
        "Sections/*",
        "ExtComponents/*",
        "Apps/*"
      ]
    },
    "docs": {
      "1": "VL Syntax Rules",
      "61": "Agent-100-Blueprint-Prompt",
      "62": "Agent-200-DataSchema-Prompt",
      "63": "Agent-250-LayoutPlan-Prompt",
      "64": "Agent-300-ContractSheet-Prompt",
      "65": "Agent-400-StateBehavior-Prompt",
      "66": "Agent-450-FileManifest-Prompt",
      "67": "Agent-610-VDB-Prompt",
      "68": "Agent-620-VTH-Prompt",
      "69": "Agent-630-VS-Prompt",
      "70": "Agent-640-CP-Prompt",
      "71": "Agent-650-SC-Prompt",
      "72": "Agent-660-VX-Prompt",
      "79": "VL-Aux-6File-Spec"
    }
  },
  "steps": [
    {
      "id": "ClearFiles_005_ClearExisting",
      "meta": {
        "title": "0. Clear existing VL files before regeneration"
      },
      "in": {},
      "out": {},
      "next": "LLM_GenBlueprint"
    },
    {
      "id": "LLM_GenBlueprint",
      "meta": {
        "title": "Phase 0: Generate Blueprint (structured requirements)"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "61"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "User Requirement:"
          },
          {
            "role": "user",
            "content": "=userRequest"
          },
          {
            "role": "user",
            "content": "Target Language:"
          },
          {
            "role": "user",
            "content": "=targetLang || 'zh-CN'"
          },
          {
            "role": "user",
            "content": "Generate Blueprint.json. This is the structured requirements file — define projectName, valueDomains, roles, entities, apps (with pages and sections), and features. Follow the 6-file spec precisely. Output ONLY valid JSON."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_object"
          }
        }
      },
      "out": {
        "$blueprint": "=_result",
        "$blueprintStr": "=_result",
        "/Process/Specs/Blueprint.json": "=_result"
      },
      "next": "Fork_Phase1"
    },
    {
      "id": "Fork_Phase1",
      "meta": {
        "title": "Phase 1: DataSchema + LayoutPlan + FileManifest (parallel)"
      },
      "children": [
        "LLM_GenDataSchema",
        "LLM_GenLayoutPlan",
        "LLM_GenFileManifest"
      ],
      "next": "LLM_GenContractSheet"
    },
    {
      "id": "LLM_GenDataSchema",
      "meta": {
        "title": "Agent-200 DataSchema"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "62"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Blueprint:"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "Generate DataSchema.json. Transform Blueprint entity drafts into precise table structures with VL types, indexes, relations, and testData. Output ONLY valid JSON."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_object"
          }
        }
      },
      "out": {
        "$dataSchema": "=_result",
        "$dataSchemaStr": "=_result",
        "/Process/Specs/DataSchema.json": "=_result"
      },
      "next": "RETURN"
    },
    {
      "id": "LLM_GenLayoutPlan",
      "meta": {
        "title": "Agent-250 LayoutPlan"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "63"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Blueprint:"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "Generate LayoutPlan.json. Define app layouts (layoutTree with containers, sections, conditionalViews, modals), section structure sketches, and extracted components. Pure visual structure — no data flow. Each app entry MUST include filePath for the final .vx file. Output ONLY valid JSON."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_object"
          }
        }
      },
      "out": {
        "$layoutPlan": "=_result",
        "$layoutPlanStr": "=_result",
        "/Process/Specs/LayoutPlan.json": "=_result"
      },
      "next": "RETURN"
    },
    {
      "id": "LLM_GenFileManifest",
      "meta": {
        "title": "Agent-450 FileManifest"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "66"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Blueprint:"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "Generate FileManifest.json. Enumerate all VL files (vdb, vth, vs, cp, sc, vx) with paths, types, generatedBy, sourceId, dependsOn, and inter-file references. REQUIRED top-level fields: files([{path,type,sourceId}]), references([{from,to,refType}]). Use format: databaseFile, themeFile, serviceFiles, componentFiles, sectionFiles, appFiles for compatibility. CRITICAL naming rules: databaseFile.path MUST be Database/<ProjectName>.vdb and themeFile.path MUST be Theme/Theme.vth. Every service/component/section/app file must include its exact final filePath. Output ONLY valid JSON."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_object"
          }
        }
      },
      "out": {
        "$fileManifest": "=_result",
        "$fileManifestStr": "=_result",
        "/Process/Specs/FileManifest.json": "=_result"
      },
      "next": "RETURN"
    },
    {
      "id": "LLM_GenContractSheet",
      "meta": {
        "title": "Phase 2: ContractSheet (depends on DataSchema)"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "64"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Blueprint:"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "DataSchema:"
          },
          {
            "role": "user",
            "content": "=$dataSchemaStr"
          },
          {
            "role": "user",
            "content": "Generate ContractSheet.json. Define: serviceDomains (with VirtualTable declarations and service signatures), sectionContracts (publicProps, publicEvents, publicMethods, consumesServices), componentContracts. All output types must be precise to field level. Output ONLY valid JSON."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_object"
          }
        }
      },
      "out": {
        "$contractSheet": "=_result",
        "$contractSheetStr": "=_result",
        "/Process/Specs/ContractSheet.json": "=_result"
      },
      "next": "LLM_GenStateBehavior"
    },
    {
      "id": "LLM_GenStateBehavior",
      "meta": {
        "title": "Phase 3: StateBehavior (depends on ContractSheet + LayoutPlan)"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "65"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Blueprint:"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "ContractSheet:"
          },
          {
            "role": "user",
            "content": "=$contractSheetStr"
          },
          {
            "role": "user",
            "content": "LayoutPlan:"
          },
          {
            "role": "user",
            "content": "=$layoutPlanStr"
          },
          {
            "role": "user",
            "content": "Generate StateBehavior.json. Define: appStates (global vars, initSequence), sectionBehaviors (keyStates, serviceBindings, initBehavior, internalMethods), eventWiring (cross-module events with handler steps), modalTriggers. keyStates types must match service output types. Output ONLY valid JSON."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_object"
          }
        }
      },
      "out": {
        "$stateBehavior": "=_result",
        "$stateBehaviorStr": "=_result",
        "/Process/Specs/StateBehavior.json": "=_result"
      },
      "next": "Set_390_SkipSpecValidation"
    },
    {
      "id": "Set_390_SkipSpecValidation",
      "meta": {
        "title": "Skip spec validation (generation-only mode)"
      },
      "target": "$specValidation",
      "value": "={\"success\":true,\"skipped\":true,\"reason\":\"validation disabled\"}",
      "next": "Fork_CodeGen"
    },
    {
      "id": "Fork_CodeGen",
      "meta": {
        "title": "Phase 4: Seed default Theme + generate all VL code in parallel"
      },
      "children": [
        "LLM_GenVDB",
        "SeedTheme_GenVTH",
        "Loop_GenVS",
        "Loop_GenCP",
        "Loop_GenSC",
        "Loop_GenVX"
      ],
      "next": "Set_590_SkipCodeValidation"
    },
    {
      "id": "LLM_GenVDB",
      "meta": {
        "title": "Generate .vdb Database"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "67"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Blueprint (valueDomains):"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "DataSchema:"
          },
          {
            "role": "user",
            "content": "=$dataSchemaStr"
          },
          {
            "role": "user",
            "content": "Generate complete VL .vdb source code based on DataSchema entities, relations, and testData. Output ONLY VL source code, no markdown fences."
          }
        ]
      },
      "out": {
        "$vdbCode": "=_result",
        "/{$fileManifest.databaseFile.path || ('Database/' + $blueprint.projectName + '.vdb')}": "=_result"
      },
      "onError": "skip",
      "next": "RETURN"
    },
    {
      "id": "SeedTheme_GenVTH",
      "meta": {
        "title": "Seed default Theme/Theme.vth"
      },
      "in": {
        "path": "Theme/Theme.vth"
      },
      "out": {
        "$vthCode": "=_result",
        "/{$fileManifest.themeFile.path || 'Theme/Theme.vth'}": "=_result"
      },
      "next": "RETURN"
    },
    {
      "id": "Loop_GenVS",
      "meta": {
        "title": "Generate all .vs Service Domains (parallel)"
      },
      "mode": "parallel",
      "source": "=$contractSheet.serviceDomains",
      "children": [
        "LLM_GenVSFile"
      ],
      "next": "RETURN"
    },
    {
      "id": "LLM_GenVSFile",
      "meta": {
        "title": "Generate .vs Service"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "69"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Service Domain:"
          },
          {
            "role": "user",
            "content": "=_item"
          },
          {
            "role": "user",
            "content": "Blueprint (valueDomains):"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "DataSchema:"
          },
          {
            "role": "user",
            "content": "=$dataSchemaStr"
          },
          {
            "role": "user",
            "content": "Generate complete VL .vs source code. Include VirtualTables and all service methods. Output ONLY VL source code, no markdown fences."
          }
        ]
      },
      "out": {
        "/{_item.filePath}": "=_result"
      },
      "onError": "skip",
      "next": "RETURN"
    },
    {
      "id": "Loop_GenCP",
      "meta": {
        "title": "Generate all .cp Components (parallel)"
      },
      "mode": "parallel",
      "source": "=$contractSheet.componentContracts",
      "children": [
        "LLM_GenCPFile"
      ],
      "next": "RETURN"
    },
    {
      "id": "LLM_GenCPFile",
      "meta": {
        "title": "Generate .cp Component"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "70"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Component Contract:"
          },
          {
            "role": "user",
            "content": "=_item"
          },
          {
            "role": "user",
            "content": "Blueprint (valueDomains):"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "LayoutPlan (preview sizes):"
          },
          {
            "role": "user",
            "content": "=$layoutPlanStr"
          },
          {
            "role": "user",
            "content": "Generate complete VL .cp source code. Pure UI component — NO service calls. Output ONLY VL source code, no markdown fences."
          }
        ]
      },
      "out": {
        "/{_item.filePath}": "=_result"
      },
      "onError": "skip",
      "next": "RETURN"
    },
    {
      "id": "Loop_GenSC",
      "meta": {
        "title": "Generate all .sc Sections (parallel)"
      },
      "mode": "parallel",
      "source": "=$contractSheet.sectionContracts",
      "children": [
        "LLM_GenSCFile"
      ],
      "next": "RETURN"
    },
    {
      "id": "LLM_GenSCFile",
      "meta": {
        "title": "Generate .sc Section"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "71"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "Section Contract:"
          },
          {
            "role": "user",
            "content": "=_item"
          },
          {
            "role": "user",
            "content": "ContractSheet (service signatures):"
          },
          {
            "role": "user",
            "content": "=$contractSheetStr"
          },
          {
            "role": "user",
            "content": "LayoutPlan (section structure):"
          },
          {
            "role": "user",
            "content": "=$layoutPlanStr"
          },
          {
            "role": "user",
            "content": "StateBehavior (state + bindings):"
          },
          {
            "role": "user",
            "content": "=$stateBehaviorStr"
          },
          {
            "role": "user",
            "content": "Blueprint (valueDomains):"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "Generate complete VL .sc source code. Section handles business logic and service calls. Output ONLY VL source code, no markdown fences."
          }
        ]
      },
      "out": {
        "/{_item.filePath}": "=_result"
      },
      "onError": "skip",
      "next": "RETURN"
    },
    {
      "id": "Loop_GenVX",
      "meta": {
        "title": "Generate all .vx Apps (parallel)"
      },
      "mode": "parallel",
      "source": "=$layoutPlan.apps",
      "children": [
        "LLM_GenVXFile"
      ],
      "next": "RETURN"
    },
    {
      "id": "LLM_GenVXFile",
      "meta": {
        "title": "Generate .vx App"
      },
      "in": {
        "stream": true,
        "docs": [
          "1",
          "79",
          "72"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "App Layout:"
          },
          {
            "role": "user",
            "content": "=_item"
          },
          {
            "role": "user",
            "content": "ContractSheet (section interfaces):"
          },
          {
            "role": "user",
            "content": "=$contractSheetStr"
          },
          {
            "role": "user",
            "content": "StateBehavior (event wiring):"
          },
          {
            "role": "user",
            "content": "=$stateBehaviorStr"
          },
          {
            "role": "user",
            "content": "Blueprint (valueDomains):"
          },
          {
            "role": "user",
            "content": "=$blueprintStr"
          },
          {
            "role": "user",
            "content": "Generate complete VL .vx source code. App manages routing, section placement, and cross-section event wiring. Output ONLY VL source code, no markdown fences."
          }
        ]
      },
      "out": {
        "/{_item.filePath || ('Apps/' + _item.appId + '.vx')}": "=_result"
      },
      "onError": "skip",
      "next": "RETURN"
    },
    {
      "id": "Set_590_SkipCodeValidation",
      "meta": {
        "title": "Phase 5: Skip generated-code validation"
      },
      "target": "$codeValidation",
      "value": "={\"success\":true,\"skipped\":true,\"reason\":\"validation disabled\"}",
      "next": "Stop_Done"
    },
    {
      "id": "Stop_Done",
      "meta": {
        "title": "Code Generation Complete"
      }
    }
  ]
}
