{
  "id": "wire.validation",
  "kind": "contract",
  "summary": "Validation codes and repair hints for Wire diagrams.",
  "useWhen": [
    "MCP save or validate returns errors",
    "a generated graph fails schema parsing",
    "an agent must recover quickly without human debugging"
  ],
  "preferredPath": [
    "Match on the stable issue code.",
    "Apply the repair hint to canonical Wire JSON.",
    "Run validate again.",
    "Only render/share after errors are gone."
  ],
  "validationRules": [
    {
      "code": "schema.invalid_type",
      "severity": "error",
      "repair": "Fix the field at the issue path. For missing node.title, add a non-empty title string."
    },
    {
      "code": "schema.invalid_union_discriminator",
      "severity": "error",
      "repair": "Use one of the supported lowercase node kinds."
    },
    {
      "code": "node.duplicate-id",
      "severity": "error",
      "repair": "Rename one node and update from, parent, children, and edge references."
    },
    {
      "code": "edge.from-missing",
      "severity": "error",
      "repair": "Add the source node or update the from reference."
    },
    {
      "code": "edge.to-missing",
      "severity": "error",
      "repair": "Add the target node or update the explicit edge target."
    },
    {
      "code": "edge.unknown-branch",
      "severity": "error",
      "repair": "Add the branch to the condition node or use a known branch name."
    },
    {
      "code": "edge.duplicate-connection",
      "severity": "error",
      "repair": "Keep one connection and remove the duplicate from ref or explicit edge."
    },
    {
      "code": "flow.no-trigger",
      "severity": "warning",
      "repair": "Add a trigger node or confirm the diagram intentionally starts elsewhere."
    },
    {
      "code": "trigger.no-outgoing",
      "severity": "warning",
      "repair": "Connect the trigger to the first workflow step."
    },
    {
      "code": "end.no-incoming",
      "severity": "warning",
      "repair": "Connect a preceding workflow step to the end node."
    },
    {
      "code": "condition.unused-branch",
      "severity": "warning",
      "repair": "Add a target node with from '<conditionId>.<branch>' or remove the unused branch."
    },
    {
      "code": "flow.unreachable",
      "severity": "warning",
      "repair": "Wire the node into a path from a trigger or add a trigger for that branch."
    },
    {
      "code": "node.card-invalid",
      "severity": "warning",
      "repair": "Keep data.card serializable and limited to title, description, badges, meta, progress, and footer."
    },
    {
      "code": "node.forbidden-field",
      "severity": "warning",
      "repair": "Replace connectsTo/connects_to with from on the target node."
    },
    {
      "code": "node.orphan",
      "severity": "warning",
      "repair": "Connect the node with from or confirm it should stay isolated."
    },
    {
      "code": "flow.cycle",
      "severity": "warning",
      "repair": "Break the loop or add a guard that explains the repeated path."
    }
  ],
  "routes": [
    {
      "path": "/llm/validation.shape.json",
      "mediaType": "application/json",
      "purpose": "Validation repair map."
    },
    {
      "path": "/llm/recipes/repair-invalid-diagram.json",
      "mediaType": "application/json",
      "purpose": "Repair loop recipe."
    }
  ],
  "related": [
    "wire.schema",
    "wire.mcp"
  ]
}
