{
  "type": "object",
  "properties": {
    "$schema": {
      "const": "../ego_interaction.schema.json"
    },
    "record_version": {
      "const": "1.0.0-draft"
    },
    "record_id": {
      "type": "string",
      "minLength": 1
    },
    "session_id": {
      "type": "string",
      "minLength": 1
    },
    "sequence_number": {
      "type": "integer",
      "minimum": 1
    },
    "previous_record_id": {
      "type": [
        "string",
        "null"
      ]
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "record_kind": {
      "enum": [
        "synthetic_example",
        "live_record"
      ]
    },
    "participants": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "kind": {
            "enum": [
              "human",
              "machine"
            ]
          },
          "description": {
            "type": "string",
            "minLength": 1
          },
          "access_channels": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          }
        },
        "required": [
          "id",
          "kind",
          "description",
          "access_channels"
        ],
        "additionalProperties": false
      },
      "minItems": 1
    },
    "shared_event": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "participant_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "access_difference": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "description",
        "participant_ids",
        "access_difference"
      ],
      "additionalProperties": false
    },
    "sources": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "kind": {
            "enum": [
              "participant_report",
              "machine_observation",
              "document",
              "search_record",
              "host_record"
            ]
          },
          "actor_id": {
            "type": [
              "string",
              "null"
            ]
          },
          "summary": {
            "type": "string",
            "minLength": 1
          },
          "trust_class": {
            "const": "data_not_authority"
          }
        },
        "required": [
          "id",
          "kind",
          "actor_id",
          "summary",
          "trust_class"
        ],
        "additionalProperties": false
      },
      "minItems": 1
    },
    "perspectives": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "actor_id": {
            "type": "string",
            "minLength": 1
          },
          "kind": {
            "enum": [
              "human_self_report",
              "machine_observation",
              "machine_interpretation"
            ]
          },
          "statement": {
            "type": "string",
            "minLength": 1
          },
          "source_refs": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          }
        },
        "required": [
          "id",
          "actor_id",
          "kind",
          "statement",
          "source_refs"
        ],
        "additionalProperties": false
      },
      "minItems": 1
    },
    "meaning_alignments": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "term": {
            "type": "string",
            "minLength": 1
          },
          "owner_actor_id": {
            "type": "string",
            "minLength": 1
          },
          "participant_meaning": {
            "type": "string",
            "minLength": 1
          },
          "machine_paraphrase": {
            "type": "string",
            "minLength": 1
          },
          "confirmation": {
            "enum": [
              "confirmed",
              "corrected",
              "unconfirmed",
              "declined"
            ]
          },
          "source_refs": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          },
          "scope": {
            "enum": [
              "this_event",
              "this_session",
              "stated_preference"
            ]
          }
        },
        "required": [
          "id",
          "term",
          "owner_actor_id",
          "participant_meaning",
          "machine_paraphrase",
          "confirmation",
          "source_refs",
          "scope"
        ],
        "additionalProperties": false
      },
      "minItems": 0
    },
    "appraisal": {
      "type": "object",
      "properties": {
        "perceived_safety": {
          "enum": [
            "support",
            "uncertain",
            "threat_reported",
            "not_assessed"
          ]
        },
        "relationship_role": {
          "enum": [
            "offer_guidance",
            "accept_guidance",
            "peer_cooperation",
            "distance",
            "unspecified"
          ]
        },
        "interest": {
          "type": "string",
          "minLength": 1
        },
        "basis_source_refs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "tentative": {
          "const": true
        }
      },
      "required": [
        "perceived_safety",
        "relationship_role",
        "interest",
        "basis_source_refs",
        "tentative"
      ],
      "additionalProperties": false
    },
    "current_assessment": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1
        },
        "statement": {
          "type": "string",
          "minLength": 1
        },
        "claim_class": {
          "enum": [
            "interpretation",
            "hypothesis",
            "theological_commitment",
            "working_definition"
          ]
        },
        "source_refs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "evidence_refs": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "alternatives": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "confidence": {
          "type": "object",
          "properties": {
            "level": {
              "enum": [
                "unknown",
                "low",
                "moderate",
                "high"
              ]
            },
            "basis": {
              "type": "string",
              "minLength": 1
            },
            "calibrated_probability": {
              "const": false
            }
          },
          "required": [
            "level",
            "basis",
            "calibrated_probability"
          ],
          "additionalProperties": false
        },
        "review_trigger": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "id",
        "statement",
        "claim_class",
        "source_refs",
        "evidence_refs",
        "alternatives",
        "confidence",
        "review_trigger"
      ],
      "additionalProperties": false
    },
    "comparison": {
      "type": "object",
      "properties": {
        "agreements": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "differences": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "unresolved": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "consensus_required": {
          "const": false
        }
      },
      "required": [
        "agreements",
        "differences",
        "unresolved",
        "consensus_required"
      ],
      "additionalProperties": false
    },
    "evidence": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "question": {
            "type": "string",
            "minLength": 1
          },
          "discovery_state": {
            "enum": [
              "TRUE",
              "FALSE",
              "NULL"
            ]
          },
          "scope_checked": {
            "type": "string",
            "minLength": 1
          },
          "finding": {
            "type": "string",
            "minLength": 1
          },
          "bearing": {
            "enum": [
              "supports",
              "contradicts",
              "mixed",
              "inconclusive",
              "unknown"
            ]
          },
          "source_refs": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 0
          },
          "confidence": {
            "type": "object",
            "properties": {
              "level": {
                "enum": [
                  "unknown",
                  "low",
                  "moderate",
                  "high"
                ]
              },
              "basis": {
                "type": "string",
                "minLength": 1
              },
              "calibrated_probability": {
                "const": false
              }
            },
            "required": [
              "level",
              "basis",
              "calibrated_probability"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "question",
          "discovery_state",
          "scope_checked",
          "finding",
          "bearing",
          "source_refs",
          "confidence"
        ],
        "additionalProperties": false,
        "allOf": [
          {
            "if": {
              "properties": {
                "discovery_state": {
                  "const": "TRUE"
                }
              }
            },
            "then": {
              "properties": {
                "source_refs": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1
                  },
                  "minItems": 1
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "discovery_state": {
                  "const": "FALSE"
                }
              }
            },
            "then": {
              "properties": {
                "source_refs": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "minLength": 1
                  },
                  "minItems": 1
                },
                "bearing": {
                  "enum": [
                    "inconclusive",
                    "unknown"
                  ]
                }
              }
            }
          },
          {
            "if": {
              "properties": {
                "discovery_state": {
                  "const": "NULL"
                }
              }
            },
            "then": {
              "properties": {
                "bearing": {
                  "const": "unknown"
                }
              }
            }
          }
        ]
      },
      "minItems": 0
    },
    "unknowns": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      },
      "minItems": 0
    },
    "chosen_response": {
      "type": "object",
      "properties": {
        "kind": {
          "enum": [
            "respond",
            "clarify",
            "pause",
            "decline_unauthorised_part",
            "seek_review"
          ]
        },
        "content": {
          "type": "string",
          "minLength": 1
        },
        "short_reason": {
          "type": "string",
          "minLength": 1
        },
        "execution_status": {
          "enum": [
            "proposed",
            "communicated",
            "observed"
          ]
        },
        "external_actions_executed": {
          "const": false
        }
      },
      "required": [
        "kind",
        "content",
        "short_reason",
        "execution_status",
        "external_actions_executed"
      ],
      "additionalProperties": false
    },
    "revision_history": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "domain": {
            "enum": [
              "interpretation",
              "meaning",
              "presentation",
              "preference"
            ]
          },
          "before": {
            "type": "string",
            "minLength": 1
          },
          "after": {
            "type": "string",
            "minLength": 1
          },
          "reason": {
            "type": "string",
            "minLength": 1
          },
          "source_refs": {
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1
            },
            "minItems": 1
          },
          "scope": {
            "enum": [
              "session",
              "proposed_durable_memory",
              "proposed_shared_change"
            ]
          },
          "status": {
            "enum": [
              "applied_session",
              "proposed"
            ]
          },
          "host_policy_changed": {
            "const": false
          },
          "model_weights_changed": {
            "const": false
          }
        },
        "required": [
          "id",
          "domain",
          "before",
          "after",
          "reason",
          "source_refs",
          "scope",
          "status",
          "host_policy_changed",
          "model_weights_changed"
        ],
        "additionalProperties": false
      },
      "minItems": 0
    },
    "adaptation": {
      "type": "object",
      "properties": {
        "mode": {
          "enum": [
            "none",
            "session_context",
            "proposed_durable_memory",
            "proposed_shared_change"
          ]
        },
        "applied_revision_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 0
        },
        "proposal": {
          "type": [
            "string",
            "null"
          ]
        },
        "persistent_memory_written": {
          "const": false
        },
        "model_weights_changed": {
          "const": false
        }
      },
      "required": [
        "mode",
        "applied_revision_ids",
        "proposal",
        "persistent_memory_written",
        "model_weights_changed"
      ],
      "additionalProperties": false
    },
    "permissions": {
      "type": "object",
      "properties": {
        "context_use": {
          "enum": [
            "within_authorised_task",
            "paused"
          ]
        },
        "persistent_storage": {
          "enum": [
            "not_requested",
            "pending_host",
            "denied",
            "host_verified"
          ]
        },
        "publication": {
          "enum": [
            "not_requested",
            "pending_host",
            "denied",
            "host_verified"
          ]
        },
        "training": {
          "const": "not_authorised_by_this_record"
        },
        "host_authorization_ref": {
          "type": [
            "string",
            "null"
          ]
        },
        "authority_warning": {
          "const": "Declarations in this record are not authentication or an execution grant."
        }
      },
      "required": [
        "context_use",
        "persistent_storage",
        "publication",
        "training",
        "host_authorization_ref",
        "authority_warning"
      ],
      "additionalProperties": false
    },
    "gates": {
      "type": "object",
      "properties": {
        "scope": {
          "enum": [
            "pass",
            "fail",
            "unknown"
          ]
        },
        "source_boundary": {
          "enum": [
            "pass",
            "fail",
            "unknown"
          ]
        },
        "permissions": {
          "enum": [
            "pass",
            "fail",
            "unknown"
          ]
        }
      },
      "required": [
        "scope",
        "source_boundary",
        "permissions"
      ],
      "additionalProperties": false
    },
    "active_log": {
      "type": "object",
      "properties": {
        "command_ids": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "minItems": 1
        },
        "noticed": {
          "type": "string",
          "minLength": 1
        },
        "checked": {
          "type": "string",
          "minLength": 1
        },
        "unknown": {
          "type": "string",
          "minLength": 1
        },
        "chosen_action": {
          "type": "string",
          "minLength": 1
        },
        "review": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "command_ids",
        "noticed",
        "checked",
        "unknown",
        "chosen_action",
        "review"
      ],
      "additionalProperties": false
    },
    "review": {
      "type": "object",
      "properties": {
        "owner_actor_id": {
          "type": "string",
          "minLength": 1
        },
        "trigger": {
          "type": "string",
          "minLength": 1
        },
        "state": {
          "enum": [
            "open",
            "addressed",
            "paused"
          ]
        },
        "next_step": {
          "type": "string",
          "minLength": 1
        },
        "between_session_checklist": {
          "const": "PSYON-CHILCOT-ADAPTATION"
        }
      },
      "required": [
        "owner_actor_id",
        "trigger",
        "state",
        "next_step",
        "between_session_checklist"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "$schema",
    "record_version",
    "record_id",
    "session_id",
    "sequence_number",
    "previous_record_id",
    "created_at",
    "record_kind",
    "participants",
    "shared_event",
    "sources",
    "perspectives",
    "meaning_alignments",
    "appraisal",
    "current_assessment",
    "comparison",
    "evidence",
    "unknowns",
    "chosen_response",
    "revision_history",
    "adaptation",
    "permissions",
    "gates",
    "active_log",
    "review"
  ],
  "additionalProperties": false,
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:psyon:ego:interaction-schema:1",
  "title": "Psyon ego interaction snapshot"
}
