{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "nt-engine-contract.v0.schema.json",
  "title": "Neverthought epistemic-assurance engine contract v0",
  "description": "Request and response shapes for the local assurance engine (nt-engine:0.1.0). An assurance rules engine, not an insurance rules engine: it evaluates declared crossings against versioned policy and never scores, prices, quotes, binds, decides coverage or claims, or certifies. The HTTP routes named in each request are the proposed hosted service; locally they are functions.",
  "$defs": {
    "sha": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
    "boundary": {
      "type": "object",
      "required": ["decision_kind", "not_an_insurance_decision", "not_a_risk_score", "not_a_certification"],
      "properties": {
        "decision_kind": { "const": "assurance_appraisal" },
        "not_an_insurance_decision": { "const": true },
        "not_a_risk_score": { "const": true },
        "not_a_certification": { "const": true }
      }
    },
    "context": {
      "description": "Recorded for audit; never an input to the gate.",
      "type": ["object", "null"], "additionalProperties": false,
      "properties": { "payment_status": { "type": "string" }, "insurer_interest": { "type": "string" }, "broker_referral": { "type": "string" }, "agent_recommendation": { "type": "string" }, "human_review_status": { "type": "string" } }
    },
    "assurance_response": {
      "allOf": [{ "$ref": "#/$defs/boundary" }],
      "type": "object",
      "required": ["contract_version", "engine_version", "operation", "workspace_id", "receipt_ref", "outcome", "outcome_label", "reason_codes", "uncertainty", "pinned", "input_hashes", "replay", "standing", "non_claims", "log"],
      "properties": {
        "contract_version": { "const": "nt-engine-contract:v0" },
        "engine_version": { "type": "string" },
        "operation": { "enum": ["appraisal", "reassessment", "replay"] },
        "workspace_id": { "type": "string" },
        "receipt_ref": { "type": "string" },
        "outcome": { "enum": ["EXECUTE", "HOLD"] },
        "outcome_label": { "enum": ["EXECUTE", "HOLD", "UNRESOLVED"], "description": "UNRESOLVED when the only reason for HOLD is UNRESOLVED disagreement." },
        "reason_codes": { "type": "array", "items": { "type": "string" } },
        "uncertainty": {
          "type": "object", "required": ["value", "structure"],
          "properties": {
            "value": { "type": "object", "required": ["status", "reasons"], "properties": { "status": { "enum": ["known", "pending", "disputed"] }, "reasons": { "type": "array" } } },
            "structure": { "type": "object", "required": ["status", "reasons", "review_state"], "properties": { "status": { "enum": ["untested", "challenged", "supported"] }, "reasons": { "type": "array" }, "review_state": { "enum": ["none", "candidate", "confirmed"] } } }
          }
        },
        "pinned": {
          "type": "object", "required": ["engine_version", "contract_version", "schema_versions", "class_ref", "policy_ref", "redaction"],
          "properties": { "class_ref": { "type": "string", "pattern": "^ntc:" }, "policy_ref": { "type": "string", "pattern": "^ntp:" }, "redaction": { "type": ["string", "null"] } }
        },
        "input_hashes": {
          "type": "object", "required": ["proposal_digest", "evidence"],
          "properties": { "proposal_digest": { "$ref": "#/$defs/sha" }, "evidence": { "type": "array", "items": { "type": "object", "required": ["id", "sha256"] } } }
        },
        "replay": { "type": "object", "required": ["status", "log_integrity"], "properties": { "status": { "enum": ["reproduces", "differs", "not_run"] }, "log_integrity": { "enum": ["verifies", "broken"] } } },
        "standing": { "type": "object", "required": ["effect", "causes", "effective", "requires_review"] },
        "non_claims": { "type": "array", "minItems": 1, "items": { "type": "string" } },
        "log": { "type": "object", "required": ["seq", "hash"], "properties": { "seq": { "type": "integer" }, "hash": { "$ref": "#/$defs/sha" } } }
      }
    },
    "agent_audit_event": {
      "description": "Every agent action creates one. Agents may read and propose only; an event never performs its action.",
      "type": "object", "additionalProperties": false,
      "required": ["agent_role", "action", "workspace_id", "authority_scope", "input_hashes", "policy_version", "tool_calls", "proposed_output_hash", "approval_required", "recorded_at"],
      "properties": {
        "agent_role": { "enum": ["intake_agent", "evidence_agent", "appraisal_agent", "replay_agent", "observation_agent", "export_agent", "security_agent"] },
        "action": { "type": "string", "pattern": "^proposed_[a-z_]+$" },
        "workspace_id": { "type": "string", "minLength": 1 },
        "authority_scope": { "const": "read_and_propose" },
        "input_hashes": { "type": "array", "items": { "$ref": "#/$defs/sha" } },
        "policy_version": { "type": "string", "minLength": 1 },
        "tool_calls": { "type": "array", "items": { "type": "string" } },
        "proposed_output_hash": { "$ref": "#/$defs/sha" },
        "approval_required": { "type": "boolean" },
        "recorded_at": { "type": "string", "minLength": 1 }
      }
    },
    "export_request": {
      "description": "POST /v1/exports. Recipient-scoped, purpose-bound, read-only; requires the owner's recorded approval.",
      "type": "object", "required": ["workspace_id", "actor", "export_id", "recipient", "purpose", "receipt_refs", "approval", "recorded_at"],
      "properties": {
        "recipient": { "type": "object", "required": ["kind", "id"], "properties": { "kind": { "enum": ["insurer", "broker", "evaluator", "owner"] }, "id": { "type": "string" } } },
        "purpose": { "type": "string", "minLength": 1 },
        "approval": { "type": "object", "required": ["approved_by", "approved_at"] },
        "context": { "$ref": "#/$defs/context" }
      }
    },
    "observation_response": {
      "description": "POST /v1/observations. Says whether the observation is independent, whether it matches a declared path, and why U_S changes or not.",
      "allOf": [{ "$ref": "#/$defs/boundary" }],
      "type": "object", "required": ["observation_id", "independent", "matches_declared_path", "structure_effect", "structure"]
    }
  },
  "not_built": {
    "description": "Routes this engine must never have.",
    "routes": ["GET /risk-score", "POST /premium", "POST /quote", "POST /bind-cover", "POST /coverage-decision", "POST /underwriting-recommendation", "POST /claims-decision", "POST /certify-discovery"]
  }
}
