{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://sediment.so/schemas/derived-artifacts/merge-retention/v2.json",
  "title": "MergeRetention",
  "description": "One attributed file measured at pull request merge.",
  "type": "object",
  "properties": {
    "org_id": {
      "type": "string",
      "pattern": "^[^\\u0000\\uD800-\\uDFFF]*$",
      "description": "The deployment's tenant id, normalized. Bound to the server."
    },
    "repo": {
      "type": "string",
      "pattern": "^[^\\u0000\\uD800-\\uDFFF]*$",
      "description": "`owner/repo`, lowercased. Empty string when the sender omitted it."
    },
    "pr_number": {
      "type": "integer",
      "description": "The positive pull request number within the repository."
    },
    "merge_id": {
      "type": "string",
      "pattern": "^[^\\u0000\\uD800-\\uDFFF]*$",
      "description": "Stable id for this pull request merge boundary."
    },
    "inference_call_id": {
      "type": "string",
      "pattern": "^[^\\u0000\\uD800-\\uDFFF]*$",
      "description": "Id of the inference call this record belongs to."
    },
    "session_id": {
      "type": "string",
      "pattern": "^[^\\u0000\\uD800-\\uDFFF]*$",
      "description": "The coding-agent session this belongs to (ADR 0002)."
    },
    "source_commit_sha": {
      "type": "string",
      "description": "The attributed source commit."
    },
    "source_file_path": {
      "type": "string",
      "description": "The attributed source path."
    },
    "head_commit_sha": {
      "type": "string",
      "description": "The final pull request head commit."
    },
    "head_file_path": {
      "type": "string",
      "description": "The source path resolved at the final pull request head."
    },
    "merge_commit_sha": {
      "type": "string",
      "description": "The merged commit boundary."
    },
    "merge_file_path": {
      "type": "string",
      "description": "The source path resolved at the merged commit boundary."
    },
    "head_retention_score": {
      "type": "number",
      "description": "Four-gram containment of the source addition at the final head."
    },
    "merge_retention_score": {
      "type": "number",
      "description": "Four-gram containment of the source addition at the merged commit."
    },
    "attribution_source": {
      "enum": [
        "git_notes",
        "jaccard"
      ],
      "type": "string",
      "description": "How the underlying attribution was established."
    },
    "attribution_similarity_score": {
      "type": "number",
      "description": "The similarity score from the source Attribution."
    },
    "provenance": {
      "$ref": "#/$defs/Provenance",
      "description": "The structured provenance for this artifact."
    },
    "session_commit_observation_ids": {
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[^\\u0000\\uD800-\\uDFFF]*$"
      },
      "description": "Sorted unique observations of the Session on the source commit. The selected call/file Attribution remains inferred."
    }
  },
  "additionalProperties": false,
  "required": [
    "org_id",
    "repo",
    "pr_number",
    "merge_id",
    "inference_call_id",
    "session_id",
    "source_commit_sha",
    "source_file_path",
    "head_commit_sha",
    "head_file_path",
    "merge_commit_sha",
    "merge_file_path",
    "head_retention_score",
    "merge_retention_score",
    "attribution_source",
    "attribution_similarity_score",
    "provenance",
    "session_commit_observation_ids"
  ],
  "$defs": {
    "Provenance": {
      "type": "object",
      "properties": {
        "policy_version": {
          "type": "string",
          "description": "The derivation implementation policy version."
        },
        "quarantine_revision": {
          "type": "integer",
          "description": "The integer quarantine-log high-water mark used for the derivation."
        },
        "policy_digest": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "description": "SHA-256 of the fully resolved derivation policy when available."
        }
      },
      "additionalProperties": false,
      "required": [
        "policy_version",
        "quarantine_revision",
        "policy_digest"
      ]
    }
  }
}
