{
  "version": "3.16",
  "name": "FeatureAdjust",
  "description": "Add or modify a feature in an existing page/section — e.g., add a button, add a form field, add a chart, modify event behavior. More granular than add-page (which creates a whole new page).",
  "sectionMerge": true,
  "registry": {
    "params": [
      "featureRequest(STRING)",
      "currentMeta(OBJECT)"
    ],
    "services": [],
    "apis": [],
    "components": [],
    "vars": [
      "$featurePlan(OBJECT)",
      "$affectedSections(ARRAY)",
      "$affectedServices(ARRAY)",
      "$newComponents(ARRAY)",
      "$updatedMeta(OBJECT)"
    ],
    "files": {
      "inputs": [
        ".vl-code/ProjectMeta.json",
        "Sections/*",
        "Services/*",
        "ExtComponents/*"
      ],
      "artifacts": [
        ".vl-code/ProjectMeta.json",
        "Sections/*",
        "Services/*",
        "ExtComponents/*"
      ]
    },
    "docs": {
      "1": "VL 3.7 Syntax Rules"
    }
  },
  "steps": [
    {
      "id": "LLM_010_PlanFeature",
      "meta": {
        "title": "1. Analyze project and plan feature changes"
      },
      "in": {
        "docs": [
          "1"
        ],
        "max_tokens": 32768,
        "messages": [
          {
            "role": "user",
            "content": "You are a VL project architect. Analyze the current project and plan how to add/modify the requested feature.\n\nCurrent ProjectMeta:"
          },
          {
            "role": "user",
            "content": "=currentMeta"
          },
          {
            "role": "user",
            "content": "Feature request:"
          },
          {
            "role": "user",
            "content": "=featureRequest"
          },
          {
            "role": "user",
            "content": "Return a JSON plan with:\n- summary: one-line description of the change\n- affectedSections: [{name, file, changes: string}] — existing sections to modify\n- affectedServices: [{name, file, changes: string}] — existing services to modify\n- newComponents: [{name, description}] — new components to create (if any)\n- dbChanges: [{table, changes: string}] — database changes (if any)\n- updatedMeta: the FULL updated ProjectMeta reflecting the changes\n\nOnly include items that actually need changes. Prefer modifying existing files over creating new ones."
          }
        ],
        "output_config": {
          "format": {
            "type": "json_object"
          }
        },
        "stream": true
      },
      "out": {
        "$featurePlan": "=_result",
        "$affectedSections": "=_result.affectedSections",
        "$affectedServices": "=_result.affectedServices",
        "$newComponents": "=_result.newComponents",
        "$updatedMeta": "=_result.updatedMeta"
      },
      "next": "Pause_020_ReviewPlan"
    },
    {
      "id": "Pause_020_ReviewPlan",
      "meta": {
        "title": "2. Review feature plan (developer checkpoint)"
      },
      "resumeResultTarget": "$approved",
      "next": "Branch_030_CheckApproval"
    },
    {
      "id": "Branch_030_CheckApproval",
      "meta": {
        "title": "3. Check if plan was approved"
      },
      "cases": [
        {
          "condition": "=$approved === false",
          "next": "Stop_Cancelled"
        }
      ],
      "default": "Fork_040_Execute"
    },
    {
      "id": "Fork_040_Execute",
      "meta": {
        "title": "4. Execute changes in parallel"
      },
      "children": [
        "Loop_050_EditSections",
        "Loop_060_EditServices",
        "Loop_070_GenComponents"
      ],
      "next": "Set_080_UpdateMeta"
    },
    {
      "id": "Loop_050_EditSections",
      "meta": {
        "title": "4a. Edit affected sections"
      },
      "source": "=$affectedSections",
      "mode": "serial",
      "children": [
        "LLM_051_EditSection"
      ],
      "next": "RETURN"
    },
    {
      "id": "LLM_051_EditSection",
      "meta": {
        "title": "Edit section: =_item.name"
      },
      "in": {
        "docs": [
          "1"
        ],
        "max_tokens": 32768,
        "stream": true,
        "readFiles": [
          "=_item.file"
        ],
        "messages": [
          {
            "role": "user",
            "content": "You are editing an existing VL section file. Read the CURRENT file content carefully and make ONLY the changes described below.\n\nProject metadata:"
          },
          {
            "role": "user",
            "content": "=$updatedMeta"
          },
          {
            "role": "user",
            "content": "Changes to make:"
          },
          {
            "role": "user",
            "content": "=_item.changes"
          },
          {
            "role": "user",
            "content": "IMPORTANT: Output the COMPLETE updated section file. Preserve ALL existing bindings, events, and layout elements. Only add/modify what the changes require. Use VL 3.7 syntax with hyphen indentation.\n\nIMPORTANT: The file MUST start with '// VL_VERSION:3.7' as the first non-empty line."
          }
        ]
      },
      "out": {
        "/{_item.file}": "=_result"
      },
      "onError": "retry",
      "retryCount": 1
    },
    {
      "id": "Loop_060_EditServices",
      "meta": {
        "title": "4b. Edit affected services"
      },
      "source": "=$affectedServices",
      "mode": "serial",
      "children": [
        "LLM_061_EditService"
      ],
      "next": "RETURN"
    },
    {
      "id": "LLM_061_EditService",
      "meta": {
        "title": "Edit service: =_item.name"
      },
      "in": {
        "docs": [
          "1"
        ],
        "max_tokens": 32768,
        "stream": true,
        "readFiles": [
          "=_item.file"
        ],
        "messages": [
          {
            "role": "user",
            "content": "You are editing an existing VL service file. Read the CURRENT file content carefully and make ONLY the changes described below.\n\nChanges to make:"
          },
          {
            "role": "user",
            "content": "=_item.changes"
          },
          {
            "role": "user",
            "content": "Output the COMPLETE updated service file. Preserve ALL existing methods. Only add/modify what the changes require.\n\nIMPORTANT: The file MUST start with '// VL_VERSION:3.7' as the first non-empty line."
          }
        ]
      },
      "out": {
        "/{_item.file}": "=_result"
      },
      "onError": "retry",
      "retryCount": 1
    },
    {
      "id": "Loop_070_GenComponents",
      "meta": {
        "title": "4c. Generate new components (if any)"
      },
      "source": "=$newComponents",
      "mode": "parallel",
      "children": [
        "LLM_071_GenComponent"
      ],
      "next": "RETURN",
      "onError": "skip"
    },
    {
      "id": "LLM_071_GenComponent",
      "meta": {
        "title": "Generate component: =_item.name"
      },
      "in": {
        "docs": [
          "1"
        ],
        "max_tokens": 32768,
        "stream": true,
        "messages": [
          {
            "role": "user",
            "content": "Generate a new VL 3.5 component (.cp) file.\n\nComponent spec:"
          },
          {
            "role": "user",
            "content": "=_item"
          },
          {
            "role": "user",
            "content": "Project metadata:"
          },
          {
            "role": "user",
            "content": "=$updatedMeta\n\nIMPORTANT: The file MUST start with '// VL_VERSION:3.7' as the first non-empty line."
          }
        ]
      },
      "out": {
        "/{_item.filePath}": "=_result"
      },
      "onError": "skip"
    },
    {
      "id": "Set_080_UpdateMeta",
      "meta": {
        "title": "5. Update ProjectMeta"
      },
      "in": {},
      "out": {
        "/.vl-code/ProjectMeta.json": "=$updatedMeta"
      },
      "next": "Set_090_SkipValidation"
    },
    {
      "id": "Set_090_SkipValidation",
      "meta": {
        "title": "6. Skip validation (generation-only mode)"
      },
      "target": "$validationSkipped",
      "value": "=true",
      "next": "Stop_Done"
    },
    {
      "id": "Stop_Done",
      "meta": {
        "title": "Feature adjustment complete"
      }
    },
    {
      "id": "Stop_Cancelled",
      "meta": {
        "title": "Feature adjustment cancelled by developer"
      }
    }
  ]
}
