{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/shared-routine-import.schema.json",
  "title": "Shared routine import",
  "description": "What POST /v1/routines/shared/{id}/import returns. Step 1: preview (the routine with its full body, its sha256, the description, descriptionTr and argument hint exactly as they become frontmatter, the payload digest over all of them, and targetName, the local name it would get) with confirmToken and expiresAt; nothing is written. Step 2: imported, the registry entry routine-share.mjs wrote. The frontmatter is rebuilt locally and the routine is never run. A taken name is 409 name-taken, a sha256 or digest other than the previewed one 409 confirm-mismatch, a routine changed since the preview (any field) 409 state-moved, an unattended server 409 unattended-refused.",
  "type": "object",
  "additionalProperties": false,
  "required": ["contractVersion"],
  "properties": {
    "contractVersion": {
      "type": "string",
      "pattern": "^1\\.[0-9]+\\.[0-9]+$",
      "x-sensitivity": "none"
    },
    "preview": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "owner",
        "version",
        "description",
        "descriptionTr",
        "sha256",
        "digest",
        "updatedAt",
        "argumentHint",
        "body",
        "targetName"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9-]{0,63}$"
        },
        "name": {
          "type": "string"
        },
        "owner": {
          "type": "string"
        },
        "version": {
          "type": "integer",
          "minimum": 1
        },
        "description": {
          "type": "string",
          "description": "Exactly as import writes it into the frontmatter, unscrubbed; show it as text before the confirmation."
        },
        "descriptionTr": {
          "type": ["string", "null"]
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "digest": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "Hex SHA-256 of the canonical JSON of {argumentHint, body, description, descriptionTr, name}, keys sorted, no whitespace, an absent optional field as \"\" (routine-registry.mjs payloadDigest, equal to the sharing server's content digest): everything the import installs."
        },
        "updatedAt": {
          "type": ["string", "null"]
        },
        "argumentHint": {
          "type": ["string", "null"],
          "description": "Exactly as import writes it into the frontmatter, unscrubbed; show it as text before the confirmation."
        },
        "body": {
          "type": "string",
          "description": "The procedure text exactly as import installs it; its sha256 is sha256."
        },
        "targetName": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9-]{0,39}$"
        }
      }
    },
    "confirmToken": {
      "type": "string",
      "pattern": "^[A-Za-z0-9_-]{16,128}$"
    },
    "expiresAt": {
      "type": "string",
      "format": "date-time"
    },
    "imported": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name", "description", "source", "sha256", "digest", "sharedId"],
      "properties": {
        "name": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "source": {
          "type": ["string", "null"]
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        },
        "digest": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$",
          "description": "The payload digest of what was installed (routine-registry.mjs payloadDigest)."
        },
        "sharedId": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9-]{0,63}$"
        }
      }
    }
  }
}
