{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "$id": "https://github.com/gobing-ai/spur/schemas/transition-flow-workflow.schema.json",
    "title": "@gobing-ai/ts-dual-workflow-engine Transition-flow Workflow",
    "type": "object",
    "additionalProperties": false,
    "required": ["kind", "name", "initialNode", "nodes", "edges"],
    "properties": {
        "$schema": {
            "type": "string"
        },
        "kind": {
            "const": "transition-flow"
        },
        "name": {
            "type": "string",
            "minLength": 1
        },
        "version": {
            "type": "string",
            "minLength": 1,
            "description": "Optional behavior-neutral identity tag (0756). Absent = unversioned; present = a non-empty opaque literal surfaced as explicit(<literal>). Not parsed, ordered, or compatibility-checked; no registry."
        },
        "description": {
            "type": "string"
        },
        "initialNode": {
            "type": "string",
            "minLength": 1
        },
        "terminalNodes": {
            "type": "array",
            "items": {
                "type": "string",
                "minLength": 1
            }
        },
        "iterationBound": {
            "type": "integer",
            "exclusiveMinimum": 0
        },
        "vars": {
            "type": "object",
            "propertyNames": {
                "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
            },
            "additionalProperties": {
                "type": "string"
            }
        },
        "env": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "allow": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "pattern": "^[A-Za-z_][A-Za-z0-9_]*$"
                    }
                }
            }
        },
        "extensions": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "actions": {
                    "type": "array",
                    "items": {
                        "$ref": "#/$defs/relativeExtensionPath"
                    }
                },
                "guards": {
                    "type": "array",
                    "items": {
                        "$ref": "#/$defs/relativeExtensionPath"
                    }
                }
            }
        },
        "nodes": {
            "type": "array",
            "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["id"],
                "properties": {
                    "id": {
                        "type": "string",
                        "minLength": 1
                    },
                    "description": {
                        "type": "string"
                    },
                    "type": {
                        "enum": ["action", "gate", "parallel", "decision"]
                    },
                    "action": {
                        "$ref": "#/$defs/action"
                    }
                }
            }
        },
        "edges": {
            "type": "array",
            "items": {
                "type": "object",
                "additionalProperties": false,
                "required": ["from", "to"],
                "properties": {
                    "from": {
                        "type": "string",
                        "minLength": 1
                    },
                    "to": {
                        "type": "string",
                        "minLength": 1
                    },
                    "description": {
                        "type": "string"
                    },
                    "condition": {
                        "$ref": "#/$defs/guard"
                    }
                }
            }
        }
    },
    "$defs": {
        "action": {
            "type": "object",
            "additionalProperties": false,
            "required": ["kind"],
            "properties": {
                "kind": {
                    "type": "string",
                    "minLength": 1
                },
                "options": {
                    "type": "object",
                    "additionalProperties": true
                },
                "onError": {
                    "type": "string",
                    "enum": ["fail", "continue"],
                    "description": "Per-action error handling policy: 'fail' halts the run; 'continue' logs the failure and proceeds so edge conditions can route the outcome."
                }
            }
        },
        "guard": {
            "type": "object",
            "additionalProperties": false,
            "required": ["kind"],
            "properties": {
                "kind": {
                    "type": "string",
                    "minLength": 1
                },
                "options": {
                    "type": "object",
                    "additionalProperties": true
                }
            }
        },
        "relativeExtensionPath": {
            "type": "string",
            "minLength": 1,
            "description": "Relative module path; absolute paths and '..' traversal are forbidden.",
            "not": {
                "anyOf": [
                    {
                        "pattern": "^[/\\\\]"
                    },
                    {
                        "pattern": "^[A-Za-z]:[/\\\\]"
                    },
                    {
                        "pattern": "(^|[/\\\\])\\.\\.([/\\\\]|$)"
                    }
                ]
            }
        }
    }
}
