{
  "type": "object",
  "properties": {
    "profile": {
      "const": "autonomous_build_v1"
    },
    "contract_version": {
      "const": "1.0.0"
    },
    "package_id": {
      "type": "string",
      "minLength": 1
    },
    "scope": {
      "$ref": "#/$defs/scope"
    },
    "modules": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/module"
      },
      "minItems": 1
    },
    "decisions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/decision"
      },
      "minItems": 1
    },
    "use_cases": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/use_case"
      },
      "minItems": 1
    },
    "operations": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/operation"
      },
      "minItems": 1
    },
    "screens": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/screen"
      },
      "minItems": 0
    },
    "data": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/data"
      },
      "minItems": 1
    },
    "commands": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/command"
      },
      "minItems": 1
    },
    "integrations": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/integration"
      },
      "minItems": 0
    },
    "releases": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/release"
      },
      "minItems": 1
    },
    "environment": {
      "type": "object",
      "properties": {
        "bootstrap": {
          "type": "string",
          "minLength": 1
        },
        "repository_layout": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "dependency_policy": {
          "type": "string",
          "minLength": 1
        },
        "secrets": {
          "type": "string",
          "minLength": 1
        },
        "test_data": {
          "type": "string",
          "minLength": 1
        },
        "migration_strategy": {
          "type": "string",
          "minLength": 1
        },
        "observability": {
          "type": "string",
          "minLength": 1
        },
        "recovery": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "bootstrap",
        "repository_layout",
        "dependency_policy",
        "secrets",
        "test_data",
        "migration_strategy",
        "observability",
        "recovery"
      ],
      "additionalProperties": false
    },
    "precedence": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "minItems": 1
    }
  },
  "required": [
    "profile",
    "contract_version",
    "package_id",
    "scope",
    "modules",
    "decisions",
    "use_cases",
    "operations",
    "screens",
    "data",
    "commands",
    "integrations",
    "releases",
    "environment",
    "precedence"
  ],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$defs": {
    "decision": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "topic": {
          "type": "string",
          "minLength": 1
        },
        "authority": {
          "enum": [
            "package_default",
            "factory_delegated",
            "external_prerequisite"
          ]
        },
        "resolution": {
          "type": "string",
          "minLength": 1
        },
        "constraints": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "verification": {
          "type": "string",
          "minLength": 1
        },
        "blocks_build": {
          "type": "boolean"
        },
        "blocks_live": {
          "type": "boolean"
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        }
      },
      "required": [
        "id",
        "topic",
        "authority",
        "resolution",
        "constraints",
        "verification",
        "blocks_build",
        "blocks_live",
        "requirement_ids"
      ],
      "additionalProperties": false
    },
    "observation": {
      "type": "object",
      "properties": {
        "source": {
          "enum": [
            "http",
            "database",
            "browser",
            "metric",
            "artifact",
            "event"
          ]
        },
        "pointer": {
          "type": "string",
          "pattern": "^/"
        },
        "operator": {
          "enum": [
            "eq",
            "gte",
            "lte",
            "contains",
            "absent"
          ]
        },
        "expected": {},
        "capture": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "source",
        "pointer",
        "operator",
        "expected",
        "capture"
      ],
      "additionalProperties": false
    },
    "scenario": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "category": {
          "enum": [
            "primary",
            "alternate",
            "validation",
            "authorization",
            "isolation",
            "concurrency",
            "idempotency",
            "failure_recovery",
            "boundary"
          ]
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "initial_state": {
          "type": "object"
        },
        "request": {
          "type": "object"
        },
        "expected": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/observation"
          },
          "minItems": 1
        },
        "execution_status": {
          "const": "not_run_application"
        },
        "operation_id": {
          "type": "string",
          "minLength": 1
        },
        "request_expectation": {
          "enum": [
            "admissible",
            "schema_rejection"
          ]
        },
        "response_schema_pointer": {
          "type": "string",
          "pattern": "^#(?:/(?:anyOf|oneOf)/[0-9]+)?$"
        },
        "response_example": {
          "type": "object"
        },
        "setup_assertions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/setup_assertion"
          }
        }
      },
      "required": [
        "id",
        "category",
        "description",
        "initial_state",
        "request",
        "expected",
        "execution_status"
      ],
      "additionalProperties": false
    },
    "step": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "actor": {
          "type": "string",
          "minLength": 1
        },
        "action": {
          "type": "string",
          "minLength": 1
        },
        "observable_result": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "actor",
        "action",
        "observable_result"
      ],
      "additionalProperties": false
    },
    "use_case": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "actor": {
          "type": "string",
          "minLength": 1
        },
        "preconditions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "trigger": {
          "type": "string",
          "minLength": 1
        },
        "steps": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/step"
          },
          "minItems": 3
        },
        "postconditions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "operation_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "screen_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "data_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "scenarios": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/scenario"
          },
          "minItems": 3
        },
        "source_acceptance_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "coverage_decisions": {
          "type": "array",
          "minItems": 9,
          "maxItems": 9,
          "items": {
            "type": "object",
            "properties": {
              "category": {
                "enum": [
                  "primary",
                  "alternate",
                  "validation",
                  "authorization",
                  "isolation",
                  "concurrency",
                  "idempotency",
                  "failure_recovery",
                  "boundary"
                ]
              },
              "applies": {
                "type": "boolean"
              },
              "reason": {
                "type": "string",
                "minLength": 1
              },
              "basis": {
                "enum": [
                  "present",
                  "covered_elsewhere",
                  "not_relevant"
                ]
              },
              "scenario_ids": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "uniqueItems": true
              },
              "decision_ref": {
                "type": [
                  "string",
                  "null"
                ]
              }
            },
            "required": [
              "category",
              "applies",
              "reason"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "id",
        "title",
        "requirement_ids",
        "actor",
        "preconditions",
        "trigger",
        "steps",
        "postconditions",
        "operation_ids",
        "screen_ids",
        "data_ids",
        "scenarios",
        "source_acceptance_ids",
        "coverage_decisions"
      ],
      "additionalProperties": false
    },
    "operation": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "enum": [
            "http",
            "worker",
            "verification"
          ]
        },
        "method": {
          "enum": [
            "GET",
            "POST",
            "PUT",
            "PATCH",
            "DELETE",
            "NONE"
          ]
        },
        "path": {
          "type": "string",
          "minLength": 1
        },
        "request_schema": {
          "type": "object"
        },
        "response_schema": {
          "type": "object"
        },
        "allowed_roles": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "permission": {
          "type": "string",
          "minLength": 1
        },
        "idempotency": {
          "type": "string",
          "minLength": 1
        },
        "concurrency": {
          "type": "string",
          "minLength": 1
        },
        "transaction": {
          "type": "string",
          "minLength": 1
        },
        "errors": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "data_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "side_effects": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "timeout_ms": {
          "type": "integer",
          "minimum": 1
        },
        "outcome_constraints": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/outcome_constraint"
          }
        },
        "transition_contract": {
          "type": "object",
          "properties": {
            "data_id": {
              "type": "string",
              "minLength": 1
            },
            "initial_pointer": {
              "type": "string",
              "pattern": "^/"
            },
            "request_pointer": {
              "type": "string",
              "pattern": "^/"
            },
            "response_pointer": {
              "type": "string",
              "pattern": "^/"
            }
          },
          "required": [
            "data_id",
            "initial_pointer",
            "request_pointer",
            "response_pointer"
          ],
          "additionalProperties": false
        },
        "response_source": {
          "enum": [
            "http",
            "artifact"
          ]
        }
      },
      "required": [
        "id",
        "name",
        "kind",
        "method",
        "path",
        "request_schema",
        "response_schema",
        "allowed_roles",
        "permission",
        "idempotency",
        "concurrency",
        "transaction",
        "errors",
        "requirement_ids",
        "data_ids",
        "side_effects",
        "timeout_ms"
      ],
      "additionalProperties": false
    },
    "field": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "schema": {
          "type": "object"
        },
        "required": {
          "type": "boolean"
        },
        "validation_message": {
          "type": "string",
          "minLength": 1
        },
        "sensitive": {
          "type": "boolean"
        },
        "presentation": {
          "enum": [
            "input",
            "select",
            "hidden"
          ]
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/field"
          }
        }
      },
      "required": [
        "name",
        "label",
        "schema",
        "required",
        "validation_message",
        "sensitive"
      ],
      "additionalProperties": false
    },
    "form": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "operation_id": {
          "type": "string",
          "minLength": 1
        },
        "fields": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/field"
          },
          "minItems": 0
        },
        "confirmation": {
          "type": "string",
          "minLength": 1
        },
        "success": {
          "type": "string",
          "minLength": 1
        },
        "failure": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "title",
        "operation_id",
        "fields",
        "confirmation",
        "success",
        "failure"
      ],
      "additionalProperties": false
    },
    "screen": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "route": {
          "type": "string",
          "minLength": 1
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "roles": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "states": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "forms": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/form"
          },
          "minItems": 1
        },
        "accessibility": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "navigation": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        }
      },
      "required": [
        "id",
        "route",
        "title",
        "roles",
        "requirement_ids",
        "states",
        "forms",
        "accessibility",
        "navigation"
      ],
      "additionalProperties": false
    },
    "data": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "scope": {
          "type": "string",
          "minLength": 1
        },
        "fields": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string",
                "minLength": 1
              },
              "schema": {
                "type": "object"
              },
              "required": {
                "type": "boolean"
              },
              "description": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "name",
              "schema",
              "required",
              "description"
            ],
            "additionalProperties": false
          },
          "minItems": 1
        },
        "primary_key": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "unique_constraints": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          },
          "minItems": 0
        },
        "foreign_keys": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "field": {
                "type": "string",
                "minLength": 1
              },
              "target_data_id": {
                "type": "string",
                "minLength": 1
              },
              "target_field": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "field",
              "target_data_id",
              "target_field"
            ],
            "additionalProperties": false
          },
          "minItems": 0
        },
        "indexes": {
          "type": "array",
          "items": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          },
          "minItems": 0
        },
        "invariants": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "lifecycle": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "retention": {
          "type": "string",
          "minLength": 1
        },
        "migration": {
          "type": "string",
          "minLength": 1
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "lifecycle_field": {
          "type": "string",
          "minLength": 1
        },
        "transitions": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "from": {
                "type": "string"
              },
              "to": {
                "type": "string"
              },
              "event": {
                "type": "string"
              },
              "guard": {
                "type": "string",
                "minLength": 1
              },
              "effect": {
                "type": "string",
                "minLength": 1
              }
            },
            "required": [
              "from",
              "to",
              "event",
              "guard",
              "effect"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "id",
        "name",
        "scope",
        "fields",
        "primary_key",
        "unique_constraints",
        "foreign_keys",
        "indexes",
        "invariants",
        "lifecycle",
        "retention",
        "migration",
        "requirement_ids",
        "lifecycle_field",
        "transitions"
      ],
      "additionalProperties": false
    },
    "module": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "capability_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "use_case_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "operation_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "screen_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "data_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "release_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "boundaries": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        }
      },
      "required": [
        "id",
        "name",
        "capability_ids",
        "requirement_ids",
        "use_case_ids",
        "operation_ids",
        "screen_ids",
        "data_ids",
        "release_ids",
        "boundaries"
      ],
      "additionalProperties": false
    },
    "command": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "argv": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "timeout_seconds": {
          "type": "integer",
          "minimum": 1
        },
        "purpose": {
          "type": "string",
          "minLength": 1
        },
        "required_artifacts": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "network": {
          "enum": [
            "none",
            "declared_registry_only",
            "configured_provider_only"
          ]
        }
      },
      "required": [
        "id",
        "argv",
        "timeout_seconds",
        "purpose",
        "required_artifacts",
        "requirement_ids",
        "network"
      ],
      "additionalProperties": false
    },
    "integration": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "purpose": {
          "type": "string",
          "minLength": 1
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "mode": {
          "enum": [
            "local",
            "simulator",
            "live_prerequisite"
          ]
        },
        "request_schema": {
          "type": "object"
        },
        "response_schema": {
          "type": "object"
        },
        "timeouts": {
          "type": "string",
          "minLength": 1
        },
        "retry": {
          "type": "string",
          "minLength": 1
        },
        "deduplication": {
          "type": "string",
          "minLength": 1
        },
        "fault_cases": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "live_evidence": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "build_fallback": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "purpose",
        "requirement_ids",
        "mode",
        "request_schema",
        "response_schema",
        "timeouts",
        "retry",
        "deduplication",
        "fault_cases",
        "live_evidence",
        "build_fallback"
      ],
      "additionalProperties": false
    },
    "release": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "sequence": {
          "type": "integer",
          "minimum": 1
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "depends_on": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "command_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "completion_rule": {
          "type": "string",
          "minLength": 1
        },
        "live_gate": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "sequence",
        "requirement_ids",
        "depends_on",
        "command_ids",
        "completion_rule",
        "live_gate"
      ],
      "additionalProperties": false
    },
    "scope": {
      "type": "object",
      "properties": {
        "product_version": {
          "type": "string",
          "minLength": 1
        },
        "requirement_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "capability_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "excluded_scope": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "claim": {
          "const": "build_ready"
        }
      },
      "required": [
        "product_version",
        "requirement_ids",
        "capability_ids",
        "excluded_scope",
        "claim"
      ],
      "additionalProperties": false
    },
    "setup_assertion": {
      "type": "object",
      "properties": {
        "source_ref": {
          "type": "string",
          "minLength": 1
        },
        "left": {
          "type": "string",
          "pattern": "^/"
        },
        "operator": {
          "enum": [
            "eq",
            "ne",
            "gte",
            "lte",
            "gt",
            "lt"
          ]
        },
        "value": {},
        "right": {
          "type": "string",
          "pattern": "^/"
        }
      },
      "required": [
        "source_ref",
        "left",
        "operator"
      ],
      "additionalProperties": false,
      "oneOf": [
        {
          "required": [
            "value"
          ],
          "not": {
            "required": [
              "right"
            ]
          }
        },
        {
          "required": [
            "right"
          ],
          "not": {
            "required": [
              "value"
            ]
          }
        }
      ]
    },
    "outcome_constraint": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "when_response": {
          "type": "object"
        },
        "initial_state_schema": {
          "type": "object"
        },
        "request_schema": {
          "type": "object"
        },
        "setup_assertions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/setup_assertion"
          }
        }
      },
      "required": [
        "id",
        "when_response",
        "initial_state_schema",
        "request_schema",
        "setup_assertions"
      ],
      "additionalProperties": false
    }
  },
  "title": "OpenAgentWorks autonomous build contract 1.0"
}
