{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://caplifi.com/research/bacon-protocol/schema/agent.diplomacy.v1.json",
  "title": "agent.diplomacy.v1",
  "description": "Bacon Protocol wire envelopes (agent.diplomacy.v1). Spec: https://caplifi.com/research/bacon-protocol/. Bacon Map = drip surface; mycelium = agent network infra.",
  "type": "object",
  "required": ["protocol"],
  "properties": {
    "protocol": {
      "const": "agent.diplomacy.v1",
      "description": "Stable protocol id for the 1.x line"
    },
    "kind": {
      "const": "bacon",
      "description": "Optional envelope kind (hub-routed, agent-mediated). Implementations may omit; servers default to bacon."
    },
    "cadence_id": {
      "type": "string",
      "description": "Receipt from POST interest; agent must echo to principal (delta_only)"
    },
    "invite_principal": {
      "type": "object",
      "description": "Contract for inviting the agent's human into the protocol",
      "additionalProperties": true
    },
    "harvest": {
      "type": "object",
      "description": "Volunteered bites from the visiting agent (optional)",
      "additionalProperties": true
    },
    "semver": {
      "type": "string",
      "pattern": "^1\\.[0-9]+\\.[0-9]+$",
      "description": "Optional 1.x semver of the producing implementation"
    },
    "type": {
      "type": "string",
      "enum": ["interest", "posture", "brief", "package", "ack", "access_request", "access_status", "discovery"],
      "description": "Message type within the protocol"
    },
    "from": {
      "type": "object",
      "description": "Sender principal / agent identity",
      "properties": {
        "principal": { "type": "string" },
        "org": { "type": "string" },
        "agent": { "type": "string" },
        "contact": { "type": "string" }
      },
      "additionalProperties": true
    },
    "to": {
      "type": "object",
      "description": "Intended principal, pool, or agent",
      "properties": {
        "principal": { "type": "string" },
        "principal_pool": { "type": "string" },
        "agent": { "type": "string" }
      },
      "additionalProperties": true
    },
    "open_to": {
      "type": "object",
      "description": "Pool openness before vibes resolve a single principal",
      "additionalProperties": true
    },
    "routing": {
      "type": "object",
      "description": "Resolved hub hops and fit scores",
      "properties": {
        "pool": { "type": "string" },
        "resolved_to": { "type": ["string", "null"] },
        "hub": { "type": "string" },
        "hub_hops": { "type": "integer", "minimum": 0 },
        "fit_score": { "type": "number", "minimum": 0, "maximum": 1 }
      },
      "additionalProperties": true
    },
    "interest_class": {
      "type": "string",
      "description": "e.g. platform_intro, keep_in_touch, pilot"
    },
    "keep_in_touch": {
      "type": "boolean"
    },
    "posture": {
      "$ref": "#/$defs/posture"
    },
    "delegate_fit": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "fit": {
            "type": "array",
            "items": { "type": "string" }
          },
          "note": { "type": "string" }
        },
        "additionalProperties": true
      }
    },
    "accept_pass_along": {
      "type": "boolean",
      "description": "Sender accepts pass-along to a better-fit delegate"
    },
    "public": {
      "type": "object",
      "description": "Public brief payload safe without headgate",
      "additionalProperties": true
    },
    "consent": {
      "type": "object",
      "description": "Identify / share-more consent for headgate paths. user_attestation must be real human words when identify is true — never forged.",
      "properties": {
        "identify": { "type": "boolean" },
        "share_more": { "type": "boolean" },
        "decided": { "type": "boolean" },
        "user_attestation": {
          "type": ["string", "null"],
          "description": "What the human said when allowing naming; required if identify true"
        },
        "identity": {
          "type": ["object", "null"],
          "additionalProperties": true
        }
      },
      "additionalProperties": true
    },
    "why_for_principal": {
      "type": "string",
      "description": "Why this matters to the receiving principal (required for phone headgate)"
    },
    "slop_layer": {
      "type": "string",
      "enum": ["S0", "S1", "S2", "S3", "S4", "S5"],
      "description": "Optional networking layer tag (sense through settle)"
    }
  },
  "additionalProperties": true,
  "$defs": {
    "posture": {
      "type": "object",
      "required": ["signal", "hub"],
      "properties": {
        "signal": {
          "const": "body_language"
        },
        "hub": {
          "type": "string",
          "description": "Shared middle (company, room, graph node)"
        },
        "era": {
          "type": "string"
        },
        "cues": {
          "type": "array",
          "items": { "type": "string" }
        },
        "chemistry": {
          "type": "string",
          "enum": ["open", "neutral", "flat"]
        },
        "foot_direction": {
          "type": "string",
          "enum": ["toward", "neutral", "away"]
        },
        "hub_hops": {
          "type": "integer",
          "minimum": 0
        },
        "glyph": {
          "type": "string",
          "description": "Integrity glyph for posture cluster"
        }
      },
      "additionalProperties": true
    },
    "verdict": {
      "description": "How the receiving agent should treat the package (string or structured object)",
      "oneOf": [
        {
          "type": "string",
          "enum": ["same_room", "lean_in", "pass_along", "look_through", "ask_consent_to_identify", "warm_welcome"]
        },
        {
          "type": "object",
          "additionalProperties": true
        }
      ]
    }
  }
}
