{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://answerworthy.md/standard/0.1/schema/answerworthy-bundle.schema.json",
  "title": "Answerworthy Bundle",
  "description": "Canonical evidence-bound and agent-operable bundle defined by Answerworthy Standard 0.1.",
  "$comment": "SPDX-License-Identifier: Apache-2.0",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "standard",
    "bundle_id",
    "generated_at",
    "subject",
    "run",
    "capabilities",
    "profiles",
    "provider_states",
    "evidence",
    "findings",
    "actions",
    "projections",
    "limitations"
  ],
  "properties": {
    "standard": { "$ref": "#/$defs/standard" },
    "bundle_id": { "$ref": "#/$defs/id" },
    "generated_at": { "type": "string", "format": "date-time" },
    "subject": { "$ref": "#/$defs/subject" },
    "run": { "$ref": "#/$defs/run" },
    "capabilities": { "$ref": "#/$defs/capabilities" },
    "profiles": {
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": { "$ref": "#/$defs/profile" },
      "contains": { "const": "core" }
    },
    "provider_states": {
      "type": "array",
      "items": { "$ref": "#/$defs/provider_state" }
    },
    "evidence": {
      "type": "array",
      "items": { "$ref": "#/$defs/evidence" }
    },
    "findings": {
      "type": "array",
      "items": { "$ref": "#/$defs/finding" }
    },
    "actions": {
      "type": "array",
      "items": { "$ref": "#/$defs/action" }
    },
    "scores": {
      "type": "array",
      "items": { "$ref": "#/$defs/score" }
    },
    "projections": {
      "type": "array",
      "items": { "$ref": "#/$defs/projection" }
    },
    "limitations": {
      "type": "array",
      "minItems": 1,
      "items": { "type": "string", "minLength": 1, "maxLength": 4000 }
    },
    "extensions": {
      "type": "object",
      "propertyNames": {
        "anyOf": [
          { "format": "uri" },
          { "pattern": "^[a-z0-9]+(?:[.-][a-z0-9]+)+$" }
        ]
      },
      "additionalProperties": { "$ref": "#/$defs/json_value" }
    }
  },
  "$defs": {
    "json_value": {
      "anyOf": [
        { "type": "string" },
        { "type": "number" },
        { "type": "integer" },
        { "type": "boolean" },
        { "type": "null" },
        { "type": "array", "items": { "$ref": "#/$defs/json_value" } },
        { "type": "object", "additionalProperties": { "$ref": "#/$defs/json_value" } }
      ]
    },
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240,
      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:/-]*$"
    },
    "profile": {
      "type": "string",
      "enum": [
        "core",
        "agentic",
        "observed-web",
        "answer-probe",
        "outside-buyer",
        "recheck",
        "integrity"
      ]
    },
    "epistemic_state": {
      "type": "string",
      "enum": [
        "observed",
        "inferred",
        "founder_supplied",
        "provider_produced",
        "manual_adjudication",
        "unevaluated"
      ]
    },
    "collection_state": {
      "type": "string",
      "enum": [
        "complete",
        "partial",
        "blocked",
        "failed",
        "not_configured",
        "unavailable",
        "not_applicable"
      ]
    },
    "dimension": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "access-retrieval",
            "entity-certainty",
            "offer-comprehension",
            "evidence-corroboration",
            "buyer-question-coverage",
            "answer-performance"
          ]
        },
        {
          "type": "string",
          "pattern": "^(?:https?://|[a-z0-9]+(?:[.-][a-z0-9]+)+[:/])[A-Za-z0-9._:/-]+$"
        }
      ]
    },
    "digest": {
      "type": "object",
      "additionalProperties": false,
      "required": ["algorithm", "value"],
      "properties": {
        "algorithm": { "const": "sha256" },
        "value": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
      }
    },
    "standard": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version", "canonical_uri", "schema_uri", "status"],
      "properties": {
        "name": { "const": "Answerworthy Standard" },
        "version": { "const": "0.1.0-draft.1" },
        "canonical_uri": { "const": "https://answerworthy.md/standard/0.1" },
        "schema_uri": { "const": "https://answerworthy.md/standard/0.1/schema/answerworthy-bundle.schema.json" },
        "status": { "const": "draft" }
      }
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "canonical_url", "priority_language", "priority_market", "buyer_questions"],
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 500 },
        "public_identity": { "type": ["string", "null"], "maxLength": 500 },
        "canonical_url": { "type": "string", "format": "uri" },
        "manifest_url": { "type": ["string", "null"], "format": "uri" },
        "aliases": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1, "maxLength": 500 }
        },
        "priority_language": { "type": "string", "minLength": 1, "maxLength": 100 },
        "priority_market": { "type": "string", "minLength": 1, "maxLength": 200 },
        "buyer_questions": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1, "maxLength": 1000 }
        }
      }
    },
    "implementation": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "version"],
      "properties": {
        "name": { "type": "string", "minLength": 1, "maxLength": 300 },
        "version": { "type": "string", "minLength": 1, "maxLength": 100 },
        "uri": { "type": "string", "format": "uri" }
      }
    },
    "run_scope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["language", "market", "scope_units", "sampling_limits"],
      "properties": {
        "language": { "type": "string", "minLength": 1, "maxLength": 100 },
        "market": { "type": "string", "minLength": 1, "maxLength": 200 },
        "scope_units": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "minLength": 1, "maxLength": 100 }
        },
        "sampling_limits": {
          "type": "object",
          "additionalProperties": {
            "anyOf": [
              { "type": "integer", "minimum": 0 },
              { "type": "number", "minimum": 0 },
              { "type": "string", "minLength": 1 }
            ]
          }
        }
      }
    },
    "run": {
      "type": "object",
      "additionalProperties": false,
      "required": ["run_id", "kind", "started_at", "completed_at", "implementation", "methodology_version", "scope"],
      "properties": {
        "run_id": { "$ref": "#/$defs/id" },
        "kind": { "type": "string", "enum": ["initial", "recheck", "imported"] },
        "started_at": { "type": "string", "format": "date-time" },
        "completed_at": { "type": "string", "format": "date-time" },
        "implementation": { "$ref": "#/$defs/implementation" },
        "methodology_version": { "type": "string", "minLength": 1, "maxLength": 200 },
        "scope": { "$ref": "#/$defs/run_scope" },
        "baseline_bundle_id": {
          "anyOf": [
            { "$ref": "#/$defs/id" },
            { "type": "null" }
          ]
        }
      }
    },
    "capabilities": {
      "type": "object",
      "additionalProperties": false,
      "required": ["supported_profiles", "evidence_profiles_obtained"],
      "properties": {
        "supported_profiles": {
          "type": "array",
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/profile" }
        },
        "evidence_profiles_obtained": {
          "type": "array",
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/profile" }
        }
      }
    },
    "provider_state": {
      "type": "object",
      "additionalProperties": false,
      "required": ["provider_state_id", "provider", "kind", "status", "recorded_at", "details", "limitations"],
      "properties": {
        "provider_state_id": { "$ref": "#/$defs/id" },
        "provider": { "type": "string", "minLength": 1, "maxLength": 300 },
        "kind": {
          "type": "string",
          "enum": [
            "crawler",
            "pagespeed",
            "browser",
            "search",
            "answer_provider",
            "outside_buyer",
            "first_party_import",
            "manual_review",
            "other"
          ]
        },
        "status": { "$ref": "#/$defs/collection_state" },
        "recorded_at": { "type": "string", "format": "date-time" },
        "details": { "type": "string", "minLength": 1, "maxLength": 4000 },
        "limitations": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 4000 }
        }
      }
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": ["unit"],
      "properties": {
        "unit": {
          "type": "string",
          "enum": [
            "page",
            "sampled_site",
            "subject",
            "query",
            "provider_response",
            "public_source",
            "market",
            "language",
            "respondent",
            "import_range",
            "run",
            "other"
          ]
        },
        "language": { "type": ["string", "null"], "maxLength": 100 },
        "market": { "type": ["string", "null"], "maxLength": 200 },
        "query": { "type": ["string", "null"], "maxLength": 1000 },
        "provider": { "type": ["string", "null"], "maxLength": 300 },
        "sample_size": { "type": ["integer", "null"], "minimum": 0 }
      }
    },
    "locator": {
      "type": "object",
      "additionalProperties": false,
      "minProperties": 1,
      "properties": {
        "url": { "type": "string", "format": "uri" },
        "path": { "type": "string", "minLength": 1, "maxLength": 2000 },
        "selector": { "type": "string", "minLength": 1, "maxLength": 2000 },
        "artifact": { "type": "string", "minLength": 1, "maxLength": 2000 },
        "provider_ref": { "type": "string", "minLength": 1, "maxLength": 1000 }
      }
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "evidence_id",
        "source_class",
        "epistemic_state",
        "collection_state",
        "observed_at",
        "scope",
        "locator",
        "summary",
        "observed",
        "limitations"
      ],
      "properties": {
        "evidence_id": { "$ref": "#/$defs/id" },
        "source_class": {
          "type": "string",
          "enum": [
            "owned_web",
            "http_headers",
            "structured_data",
            "browser_render",
            "search_observation",
            "answer_provider",
            "outside_buyer",
            "first_party_import",
            "founder_context",
            "manual_review",
            "official_guidance",
            "research",
            "external_public_source",
            "other"
          ]
        },
        "epistemic_state": { "$ref": "#/$defs/epistemic_state" },
        "collection_state": { "$ref": "#/$defs/collection_state" },
        "observed_at": { "type": "string", "format": "date-time" },
        "scope": { "$ref": "#/$defs/scope" },
        "locator": { "$ref": "#/$defs/locator" },
        "summary": { "type": "string", "minLength": 1, "maxLength": 4000 },
        "observed": { "$ref": "#/$defs/json_value" },
        "digest": { "$ref": "#/$defs/digest" },
        "limitations": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 4000 }
        }
      }
    },
    "research_basis": {
      "type": "object",
      "additionalProperties": false,
      "required": ["source_id", "evidence_class", "applicability", "strength", "generalisation_limit"],
      "properties": {
        "source_id": { "type": "string", "minLength": 1, "maxLength": 500 },
        "evidence_class": {
          "type": "string",
          "enum": [
            "official_platform_guidance",
            "peer_reviewed_experiment",
            "large_observational_dataset",
            "vendor_observational_study",
            "product_methodology",
            "live_observation",
            "other"
          ]
        },
        "applicability": { "type": "string", "minLength": 1, "maxLength": 2000 },
        "strength": { "type": "string", "enum": ["direct", "supporting", "contextual", "heuristic"] },
        "generalisation_limit": { "type": "string", "minLength": 1, "maxLength": 4000 }
      }
    },
    "finding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["finding_id", "dimension", "title", "status", "severity", "confidence", "epistemic_state", "explanation", "evidence_refs"],
      "properties": {
        "finding_id": { "$ref": "#/$defs/id" },
        "dimension": { "$ref": "#/$defs/dimension" },
        "criterion_id": { "type": ["string", "null"], "maxLength": 240 },
        "title": { "type": "string", "minLength": 1, "maxLength": 500 },
        "status": { "type": "string", "enum": ["pass", "warn", "fail", "manual", "not_applicable", "unavailable"] },
        "severity": { "type": "string", "enum": ["critical", "high", "medium", "low", "info"] },
        "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
        "epistemic_state": { "$ref": "#/$defs/epistemic_state" },
        "explanation": { "type": "string", "minLength": 1, "maxLength": 8000 },
        "recommendation": { "type": ["string", "null"], "maxLength": 8000 },
        "acceptance_test": { "type": ["string", "null"], "maxLength": 4000 },
        "generalisation_note": { "type": ["string", "null"], "maxLength": 4000 },
        "unavailable_reason": { "type": ["string", "null"], "maxLength": 4000 },
        "evidence_refs": {
          "type": "array",
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/id" }
        },
        "research_basis": {
          "type": "array",
          "items": { "$ref": "#/$defs/research_basis" }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": { "status": { "enum": ["pass", "warn", "fail"] } },
            "required": ["status"]
          },
          "then": { "properties": { "evidence_refs": { "minItems": 1 } } }
        },
        {
          "if": {
            "properties": { "status": { "const": "unavailable" } },
            "required": ["status"]
          },
          "then": {
            "required": ["unavailable_reason"],
            "properties": { "unavailable_reason": { "type": "string", "minLength": 1 } }
          }
        }
      ]
    },
    "target": {
      "type": "object",
      "additionalProperties": false,
      "required": ["label"],
      "properties": {
        "label": { "type": "string", "minLength": 1, "maxLength": 1000 },
        "url": { "type": "string", "format": "uri" },
        "path": { "type": "string", "minLength": 1, "maxLength": 2000 },
        "query": { "type": "string", "minLength": 1, "maxLength": 1000 }
      }
    },
    "action": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "action_id",
        "type",
        "lane",
        "title",
        "rationale",
        "source_finding_refs",
        "targets",
        "dependencies",
        "permission_mode",
        "preconditions",
        "steps",
        "evidence_requirements",
        "guardrails",
        "definition_of_done",
        "verification",
        "expected_outcome",
        "effort",
        "impact",
        "status"
      ],
      "properties": {
        "action_id": { "$ref": "#/$defs/id" },
        "type": { "type": "string", "enum": ["remediation", "evidence_collection", "verification", "maintenance"] },
        "lane": { "type": "string", "minLength": 1, "maxLength": 200 },
        "title": { "type": "string", "minLength": 1, "maxLength": 500 },
        "rationale": { "type": "string", "minLength": 1, "maxLength": 8000 },
        "source_finding_refs": {
          "type": "array",
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/id" }
        },
        "targets": {
          "type": "array",
          "items": { "$ref": "#/$defs/target" }
        },
        "dependencies": {
          "type": "array",
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/id" }
        },
        "permission_mode": {
          "type": "string",
          "enum": ["advisory", "human_required", "agent_ready", "external_authorisation_required"]
        },
        "owner_role": { "type": ["string", "null"], "maxLength": 300 },
        "preconditions": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 4000 }
        },
        "steps": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 4000 }
        },
        "evidence_requirements": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 4000 }
        },
        "guardrails": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 4000 }
        },
        "definition_of_done": { "type": "string", "minLength": 1, "maxLength": 8000 },
        "verification": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "minLength": 1, "maxLength": 4000 }
        },
        "expected_outcome": { "type": "string", "minLength": 1, "maxLength": 4000 },
        "rollback_or_irreversibility": { "type": ["string", "null"], "maxLength": 4000 },
        "effort": { "type": "string", "enum": ["small", "medium", "large", "unknown"] },
        "impact": { "type": "string", "enum": ["low", "medium", "high", "unknown"] },
        "status": { "type": "string", "enum": ["proposed", "ready", "blocked", "in_progress", "complete", "rejected"] }
      },
      "allOf": [
        {
          "if": {
            "properties": { "permission_mode": { "const": "agent_ready" } },
            "required": ["permission_mode"]
          },
          "then": {
            "properties": {
              "preconditions": { "minItems": 1 },
              "steps": { "minItems": 1 },
              "rollback_or_irreversibility": { "type": "string", "minLength": 1 }
            }
          }
        }
      ]
    },
    "score": {
      "type": "object",
      "additionalProperties": false,
      "required": ["score_id", "dimension", "value", "scale", "evidence_state", "evidence_coverage", "evaluated_count", "applicable_count", "method", "finding_refs", "caps"],
      "properties": {
        "score_id": { "$ref": "#/$defs/id" },
        "dimension": {
          "anyOf": [
            { "$ref": "#/$defs/dimension" },
            { "const": "overall" }
          ]
        },
        "value": { "type": ["number", "null"] },
        "scale": {
          "type": "object",
          "additionalProperties": false,
          "required": ["minimum", "maximum"],
          "properties": {
            "minimum": { "type": "number" },
            "maximum": { "type": "number" }
          }
        },
        "evidence_state": { "type": "string", "enum": ["sufficient", "insufficient"] },
        "evidence_coverage": { "type": "number", "minimum": 0, "maximum": 1 },
        "evaluated_count": { "type": "integer", "minimum": 0 },
        "applicable_count": { "type": "integer", "minimum": 0 },
        "method": { "type": "string", "minLength": 1, "maxLength": 4000 },
        "finding_refs": {
          "type": "array",
          "uniqueItems": true,
          "items": { "$ref": "#/$defs/id" }
        },
        "caps": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["maximum", "reason"],
            "properties": {
              "maximum": { "type": "number" },
              "reason": { "type": "string", "minLength": 1, "maxLength": 4000 }
            }
          }
        }
      },
      "allOf": [
        {
          "if": {
            "properties": { "evidence_state": { "const": "insufficient" } },
            "required": ["evidence_state"]
          },
          "then": { "properties": { "value": { "type": "null" } } }
        }
      ]
    },
    "projection": {
      "type": "object",
      "additionalProperties": false,
      "required": ["projection_id", "kind", "path_or_uri", "media_type", "source_bundle_id", "omitted_sections", "limitations"],
      "properties": {
        "projection_id": { "$ref": "#/$defs/id" },
        "kind": { "type": "string", "enum": ["agent_markdown", "human_pdf", "human_html", "json_export", "other"] },
        "path_or_uri": { "type": "string", "minLength": 1, "maxLength": 2000 },
        "media_type": { "type": "string", "minLength": 1, "maxLength": 200 },
        "source_bundle_id": { "$ref": "#/$defs/id" },
        "digest": { "$ref": "#/$defs/digest" },
        "omitted_sections": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 500 }
        },
        "limitations": {
          "type": "array",
          "items": { "type": "string", "minLength": 1, "maxLength": 4000 }
        }
      }
    }
  }
}
