{
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "descriptor_id",
    "revision",
    "evidence_level",
    "publisher_id",
    "hardware",
    "compatibility",
    "resource_claims",
    "capabilities",
    "artifacts",
    "self_test",
    "supply_chain"
  ],
  "properties": {
    "schema_version": {
      "const": "koobique.module-descriptor.v0.1"
    },
    "descriptor_id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
    },
    "revision": {
      "type": "integer",
      "minimum": 1,
      "maximum": 2147483647
    },
    "evidence_level": {
      "enum": [
        "fixture",
        "proposed",
        "qualified"
      ]
    },
    "publisher_id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
    },
    "hardware": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "family",
        "revisions",
        "bus",
        "attach_policy",
        "identity_assurance",
        "device_profile_id"
      ],
      "properties": {
        "family": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "revisions": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 48
          },
          "minItems": 1,
          "maxItems": 32,
          "uniqueItems": true
        },
        "bus": {
          "enum": [
            "pcie",
            "usb",
            "simulated"
          ]
        },
        "attach_policy": {
          "enum": [
            "cold_plug",
            "qualified_usb_hotplug",
            "simulated"
          ]
        },
        "identity_assurance": {
          "enum": [
            "bus_observed",
            "device_key_verified"
          ]
        },
        "device_profile_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "bus": {
                "const": "pcie"
              }
            }
          },
          "then": {
            "properties": {
              "attach_policy": {
                "const": "cold_plug"
              }
            }
          }
        },
        {
          "if": {
            "properties": {
              "attach_policy": {
                "const": "qualified_usb_hotplug"
              }
            }
          },
          "then": {
            "properties": {
              "bus": {
                "const": "usb"
              }
            }
          }
        }
      ]
    },
    "compatibility": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "qualification_profile_id",
        "os_profile_id",
        "kernel_build_id",
        "driver_bundle_sha256",
        "runtime_artifact_id",
        "model_artifact_id",
        "preprocessing_artifact_id",
        "postprocessing_artifact_id",
        "dependency_lock_artifact_id",
        "accelerator_target",
        "model_format",
        "worker_ipc",
        "service_profile_id"
      ],
      "properties": {
        "qualification_profile_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "os_profile_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "kernel_build_id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "driver_bundle_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "runtime_artifact_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "model_artifact_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "preprocessing_artifact_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "postprocessing_artifact_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "dependency_lock_artifact_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "accelerator_target": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "model_format": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160
        },
        "worker_ipc": {
          "const": "koobique.worker-ipc.v1"
        },
        "service_profile_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        }
      }
    },
    "resource_claims": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "host_peak_ram_bytes",
        "device_peak_ram_bytes",
        "scratch_peak_bytes",
        "persistent_bytes",
        "max_input_bytes",
        "max_output_bytes",
        "queue_depth",
        "max_concurrency",
        "cpu_quota_percent",
        "power_profile_id",
        "thermal_profile_id",
        "claimed_peak_mw",
        "claimed_throttle_centi_c"
      ],
      "properties": {
        "host_peak_ram_bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "device_peak_ram_bytes": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "scratch_peak_bytes": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "persistent_bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 9007199254740991
        },
        "max_input_bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 16777216
        },
        "max_output_bytes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1048576
        },
        "queue_depth": {
          "type": "integer",
          "minimum": 1,
          "maximum": 128
        },
        "max_concurrency": {
          "type": "integer",
          "minimum": 1,
          "maximum": 32
        },
        "cpu_quota_percent": {
          "type": "integer",
          "minimum": 1,
          "maximum": 800
        },
        "power_profile_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "thermal_profile_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "claimed_peak_mw": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1000000
        },
        "claimed_throttle_centi_c": {
          "type": "integer",
          "minimum": 1,
          "maximum": 15000
        }
      }
    },
    "capabilities": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "revision",
          "input_schema_artifact_id",
          "output_schema_artifact_id",
          "output_kind",
          "actuation_authority",
          "requested_data_access",
          "effect_evidence"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
          },
          "revision": {
            "type": "integer",
            "minimum": 1,
            "maximum": 2147483647
          },
          "input_schema_artifact_id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
          },
          "output_schema_artifact_id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
          },
          "output_kind": {
            "enum": [
              "estimate",
              "proposal",
              "dialogue"
            ]
          },
          "actuation_authority": {
            "const": "none"
          },
          "requested_data_access": {
            "type": "array",
            "items": {
              "enum": [
                "observations_read",
                "camera_frames",
                "microphone_segments",
                "room_labels"
              ]
            },
            "minItems": 1,
            "maxItems": 8,
            "uniqueItems": true
          },
          "effect_evidence": {
            "const": false
          }
        }
      },
      "minItems": 1,
      "maxItems": 16,
      "uniqueItems": true
    },
    "artifacts": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "kind",
          "sha256",
          "size_bytes",
          "license"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
          },
          "kind": {
            "enum": [
              "runtime",
              "model",
              "preprocess",
              "postprocess",
              "ipc_schema",
              "dependency_lock",
              "self_test"
            ]
          },
          "sha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "size_bytes": {
            "type": "integer",
            "minimum": 1,
            "maximum": 9007199254740991
          },
          "license": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "expression",
              "text_sha256",
              "redistribution_review",
              "user_acceptance_required"
            ],
            "properties": {
              "expression": {
                "type": "string",
                "minLength": 1,
                "maxLength": 160
              },
              "text_sha256": {
                "type": "string",
                "pattern": "^[a-f0-9]{64}$"
              },
              "redistribution_review": {
                "enum": [
                  "pending",
                  "approved",
                  "forbidden"
                ]
              },
              "user_acceptance_required": {
                "type": "boolean"
              }
            }
          }
        }
      },
      "minItems": 1,
      "maxItems": 64,
      "uniqueItems": true
    },
    "self_test": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "artifact_id",
        "case_set_id",
        "deadline_ms",
        "expected_result_sha256"
      ],
      "properties": {
        "artifact_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "case_set_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        },
        "deadline_ms": {
          "type": "integer",
          "minimum": 1,
          "maximum": 600000
        },
        "expected_result_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      }
    },
    "supply_chain": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "target_path",
        "minimum_metadata_version",
        "delegation_role"
      ],
      "properties": {
        "target_path": {
          "type": "string",
          "pattern": "^modules/[a-z0-9][a-z0-9._-]*(?:/[a-z0-9][a-z0-9._-]*)*$",
          "maxLength": 240
        },
        "minimum_metadata_version": {
          "type": "integer",
          "minimum": 1,
          "maximum": 2147483647
        },
        "delegation_role": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]{0,127}$"
        }
      }
    }
  },
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://koobique.iqui.page/assets/research/modular-descriptor.schema.json",
  "$comment": "Research proposal. Not deployed or part of KQIP. Signature, trust, references, integer limits and runtime admission require additional checks."
}
