{
  "$id": "https://eugenelim.github.io/agent-ready-repo/docs/spec/catalogue/draft/adapter.schema.json",
  "x-spec": "docs/specs/distribution-route-contract",
  "type": "object",
  "required": ["contract", "primitive", "adapter"],
  "properties": {
    "contract": {
      "type": "object",
      "required": ["version"],
      "properties": {
        "version": {"type": "string", "pattern": "^[0-9]+\\.[0-9]+$"}
      }
    },
    "primitive": {
      "type": "object",
      "required": ["skill", "agent", "hook-body", "hook-wiring", "command"],
      "additionalProperties": {
        "type": "object",
        "required": ["source-path"],
        "properties": {
          "source-path": {"type": "string"}
        }
      }
    },
    "adapter": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "properties": {
          "projection": {
            "type": "array",
            "items": {
              "type": "object",
              "required": ["primitive", "mode"],
              "properties": {
                "primitive": {
                  "type": "string",
                  "enum": ["skill", "agent", "hook-body", "hook-wiring", "command"]
                },
                "mode": {
                  "type": "string",
                  "enum": [
                    "direct-directory",
                    "direct-file",
                    "merge-json",
                    "user-merge-json",
                    "merge-into-agent-json",
                    "instruction-file",
                    "managed-block-inline",
                    "degraded-info-log",
                    "dropped",
                    "codex-agent-toml",
                    "copilot-agent-md",
                    "copilot-hooks-json",
                    "gemini-command-toml"
                  ]
                },
                "target-path": {"type": "string"},
                "on-conflict": {
                  "type": "string",
                  "enum": [
                    "prompt-then-preserve",
                    "prompt-then-overwrite",
                    "preserve-outside-block",
                    "merge-managed-key-only",
                    "overwrite-without-prompt"
                  ]
                },
                "managed-key": {"type": "string"},
                "managed-block-delimiter-start": {"type": "string"},
                "managed-block-delimiter-end": {"type": "string"},
                "frontmatter-mapping": {"type": "string"},
                "frontmatter-default": {"type": "string"},
                "inject-resources": {"type": "array", "items": {"type": "string"}},
                "info-message": {"type": "string"}
              }
            }
          },
          "projections": {
            "type": "object",
            "additionalProperties": {
              "type": "object",
              "required": ["mode"],
              "properties": {
                "mode": {
                  "if": {"type": "string"},
                  "then": {
                    "enum": [
                      "direct-directory",
                      "direct-file",
                      "merge-json",
                      "user-merge-json",
                      "merge-into-agent-json",
                      "instruction-file",
                      "managed-block-inline",
                      "degraded-info-log",
                      "dropped",
                      "codex-agent-toml",
                      "copilot-agent-md",
                      "copilot-hooks-json",
                      "gemini-command-toml"
                    ]
                  },
                  "else": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "repo": {
                        "enum": [
                          "direct-directory",
                          "direct-file",
                          "merge-json",
                          "user-merge-json",
                          "merge-into-agent-json",
                          "instruction-file",
                          "managed-block-inline",
                          "degraded-info-log",
                          "dropped",
                          "codex-agent-toml",
                          "copilot-agent-md",
                          "copilot-hooks-json",
                          "gemini-command-toml"
                        ]
                      },
                      "user": {
                        "enum": [
                          "direct-directory",
                          "direct-file",
                          "merge-json",
                          "user-merge-json",
                          "merge-into-agent-json",
                          "instruction-file",
                          "managed-block-inline",
                          "degraded-info-log",
                          "dropped",
                          "codex-agent-toml",
                          "copilot-agent-md",
                          "copilot-hooks-json",
                          "gemini-command-toml"
                        ]
                      }
                    }
                  }
                },
                "target": {
                  "if": {"type": "string"},
                  "then": {},
                  "else": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "repo": {"type": "string"},
                      "user": {"type": "string"}
                    }
                  }
                },
                "managed-key": {
                  "if": {"type": "string"},
                  "then": {},
                  "else": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                      "repo": {"type": "string"},
                      "user": {"type": "string"}
                    }
                  }
                },
                "agent-event-vocabulary": {
                  "type": "array",
                  "minItems": 1,
                  "items": {"type": "string"}
                },
                "ide-event-vocabulary": {
                  "type": "array",
                  "minItems": 1,
                  "items": {"type": "string"}
                },
                "ide-action-vocabulary": {
                  "type": "array",
                  "minItems": 1,
                  "items": {"type": "string"}
                },
                "on-conflict": {
                  "type": "string",
                  "enum": [
                    "prompt-then-preserve",
                    "prompt-then-overwrite",
                    "preserve-outside-block",
                    "merge-managed-key-only",
                    "overwrite-without-prompt"
                  ]
                },
                "frontmatter-mapping": {"type": "string"},
                "frontmatter-default": {"type": "string"},
                "info-message": {"type": "string"}
              }
            }
          },
          "scope": {
            "type": "object",
            "required": ["repo", "allowed-prefixes"],
            "properties": {
              "repo": {"type": "string"},
              "user": {"type": "string"},
              "allowed-prefixes": {
                "type": "object",
                "required": ["repo"],
                "properties": {
                  "repo": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "string",
                      "pattern": "^((?!\\.\\.(\\/|$))[^/]+/)+$"
                    }
                  },
                  "user": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "string",
                      "pattern": "^((?!\\.\\.(\\/|$))[^/]+/)+$"
                    }
                  }
                },
                "additionalProperties": {
                  "type": "array",
                  "minItems": 1,
                  "items": {
                    "type": "string",
                    "pattern": "^((?!\\.\\.(\\/|$))[^/]+/)+$"
                  }
                }
              }
            }
          }
        }
      }
    },
    "frontmatter-mapping": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": {
          "type": "object",
          "properties": {
            "rename": {"type": "string"},
            "normalize": {
              "type": "string",
              "enum": ["to-list", "to-string", "lowercase"]
            },
            "default": {"type": "string"},
            "values": {
              "type": "object",
              "additionalProperties": {"type": "string"}
            },
            "related-values": {
              "type": "object",
              "additionalProperties": {
                "type": "object",
                "additionalProperties": {"type": "string"}
              }
            }
          }
        }
      }
    },
    "frontmatter-default": {
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": {"type": "string"}
      }
    }
  }
}
