{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://stegverse.org/schemas/stegverse.ingress-manifest.v1.schema.json",
  "title": "StegVerse ingress manifest v1",
  "description": "Processor-generic machine-to-machine ingress for externally manifested data. The source framework retains semantic custody of its payload. Processing capability, runtime route, caller-facing evidence projection, presentation stage, and governed southbound completion are distinct; none grants authority or suppresses canonical Master Records custody.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "manifest_profile",
    "manifest_profile_version",
    "source_framework",
    "source_output_id",
    "created_at",
    "declared_intent",
    "requested_consequence",
    "hashes",
    "extensions"
  ],
  "properties": {
    "manifest_profile": {"const": "stegverse.ingress-manifest.v1"},
    "manifest_profile_version": {"const": "1"},
    "source_framework": {"type": "string", "minLength": 1},
    "source_instance": {"type": ["string", "null"]},
    "source_output_id": {"type": "string", "minLength": 1},
    "created_at": {"type": "string", "minLength": 1},
    "freshness": {"type": "object"},
    "payload": {
      "description": "The source framework's manifested native data. StegVerse does not require the payload to be a StegVerse-native semantic class.",
      "type": ["object", "array", "string", "number", "boolean", "null"]
    },
    "payload_commitment": {
      "description": "A source-provided commitment used instead of an inline payload. The commitment profile declares how independent implementations verify it.",
      "type": "string",
      "minLength": 1
    },
    "payload_commitment_profile": {
      "description": "Verification profile for payload_commitment. The currently published profile is sha256.",
      "type": "string",
      "enum": ["sha256"]
    },
    "processing": {
      "description": "Caller-facing processing intent. This is distinct from runtime route mechanics. Existing v1 governance manifests that omit this object remain backward-compatible and derive governance only from the canonical governed route.",
      "type": "object",
      "additionalProperties": false,
      "required": ["capability", "route_id"],
      "properties": {
        "capability": {"type": "string", "minLength": 1},
        "route_id": {"type": "string", "minLength": 1}
      }
    },
    "candidate": {
      "description": "Processor-specific proposition. Required for governance processing, optional for other processors. It never redefines the source payload's native semantics.",
      "type": "object"
    },
    "declared_intent": {"type": "string", "minLength": 1},
    "requested_consequence": {"type": "string", "minLength": 1},
    "context_refs": {"type": "array", "items": {"type": "string"}},
    "canonicalization_profile": {"type": "string"},
    "hashes": {
      "type": "object",
      "properties": {
        "payload_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
        "candidate_sha256": {"type": "string", "pattern": "^[0-9a-f]{64}$"}
      },
      "additionalProperties": true
    },
    "attestation": {},
    "extensions": {
      "type": "object",
      "required": ["stegverse_route"],
      "properties": {
        "stegverse_route": {
          "description": "Runtime route declaration. Structural ingress accepts a route identifier generically; executable runtime resolution separately requires an installed published route and its exact route contract.",
          "type": "object",
          "required": ["route_id"],
          "properties": {
            "route_id": {"type": "string", "minLength": 1},
            "lane_class": {"type": "string"},
            "routing_surface": {"type": "string"},
            "containment": {"type": "string"},
            "sandbox_required": {"type": "boolean"},
            "external_consequence_enabled": {"type": "boolean"}
          },
          "additionalProperties": true
        },
        "stegverse_governance_request": {
          "description": "Complete governance-processor input. Required only when processing capability is governance (or for backward-compatible canonical-governed v1 manifests that omit processing). The SDK does not synthesize missing governance evidence.",
          "type": "object",
          "required": [
            "candidate",
            "judgment",
            "signal",
            "execution",
            "capability",
            "continuity",
            "approval",
            "permission_present"
          ]
        }
      },
      "additionalProperties": true
    },
    "return_projection": {
      "description": "Caller-facing artifact depth. NONE returns no transition-detail projection; SELECTED returns named transition classes; ALL returns all user-disclosable transition evidence. Canonical custody is unaffected.",
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "mode": {"type": "string", "enum": ["ALL", "SELECTED", "NONE"]},
        "transition_classes": {"type": "array", "uniqueItems": true, "items": {"type": "string", "minLength": 1}}
      }
    },
    "completion": {
      "description": "Complete governed communication lifecycle through presentation, SDK return assembly, ecosystem egress, Interlock/InTr, and the far-side transition. Legacy v1 manifests may omit this block but are not complete communication manifests.",
      "type": "object",
      "additionalProperties": false,
      "required": ["direction", "initiator", "publisher", "egress"],
      "properties": {
        "direction": {"const": "SOUTH"},
        "initiator": {
          "type": "object",
          "additionalProperties": false,
          "required": ["class", "ref"],
          "properties": {
            "class": {"type": "string", "minLength": 1},
            "ref": {"type": "string", "minLength": 1}
          }
        },
        "publisher": {
          "type": "object",
          "additionalProperties": false,
          "required": ["stage", "required", "package_profile"],
          "properties": {
            "stage": {"const": "PUBLISHER"},
            "required": {"type": "boolean"},
            "package_profile": {"type": "string", "minLength": 1}
          }
        },
        "egress": {
          "type": "object",
          "additionalProperties": false,
          "required": ["final_stegverse_transition_surface", "transport", "far_side_transition_required"],
          "properties": {
            "final_stegverse_transition_surface": {"type": "string", "minLength": 1},
            "transport": {"const": "INTERLOCK_INTR"},
            "far_side_transition_required": {"const": true},
            "destination_profile": {
              "description": "Manifest-declared Interlock/InTr destination profile. When supplied it must survive SDK return assembly and the final egress handoff unchanged; it grants no authority.",
              "type": "string",
              "minLength": 1
            }
          }
        }
      }
    },
    "manifest_labels": {"type": "object"}
  },
  "oneOf": [
    {"required": ["payload"], "not": {"required": ["payload_commitment"]}},
    {"required": ["payload_commitment", "payload_commitment_profile"], "not": {"required": ["payload"]}}
  ],
  "allOf": [
    {
      "if": {"required": ["payload"]},
      "then": {
        "properties": {"hashes": {"required": ["payload_sha256"]}},
        "not": {"required": ["payload_commitment_profile"]}
      }
    },
    {
      "if": {
        "properties": {"payload_commitment_profile": {"const": "sha256"}},
        "required": ["payload_commitment", "payload_commitment_profile"]
      },
      "then": {
        "properties": {"payload_commitment": {"pattern": "^[0-9a-f]{64}$"}}
      }
    },
    {
      "if": {
        "properties": {
          "processing": {
            "properties": {"capability": {"const": "governance"}},
            "required": ["capability"]
          }
        },
        "required": ["processing"]
      },
      "then": {
        "required": ["candidate"],
        "properties": {
          "hashes": {"required": ["candidate_sha256"]},
          "extensions": {"required": ["stegverse_route", "stegverse_governance_request"]}
        }
      }
    },
    {
      "if": {
        "not": {"required": ["processing"]},
        "properties": {
          "extensions": {
            "properties": {
              "stegverse_route": {
                "properties": {"route_id": {"const": "stegverse.route.canonical-governed.v1"}},
                "required": ["route_id"]
              }
            }
          }
        }
      },
      "then": {
        "required": ["candidate"],
        "properties": {
          "hashes": {"required": ["candidate_sha256"]},
          "extensions": {"required": ["stegverse_route", "stegverse_governance_request"]}
        }
      }
    }
  ],
  "$defs": {
    "artifact_depth_mapping": {
      "description": "Semantic mapping used by SDK documentation: governance artifact only = SELECTED governance classes; governance + transition = SELECTED governance plus transition/result classes; full state-transition artifact = ALL. NONE is a locator/minimal-return mode, not a governance-only artifact.",
      "type": "object"
    }
  }
}
