{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/peopleprincipia-com/json-schema/peopleprincipia-com-study-design-document-schema.json",
  "title": "StudyDesignDocument",
  "description": "Existing principia.study-design/1 wire document, generated from apps/web/lib/study-design/contract.ts studyDocumentSchema. Runtime additionally checks unique IDs, valid connection/check endpoints, signed selection/planning integrity and consumer metadata where present. A valid wire document is not scientific approval.",
  "x-generated": "2026-11-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/peopleprincipia-com-openapi.yaml#/components/schemas/StudyDesignDocument",
  "type": "object",
  "properties": {
    "schema": {
      "type": "string",
      "const": "principia.study-design/1"
    },
    "documentId": {
      "type": "string",
      "minLength": 1,
      "maxLength": 120,
      "pattern": "^[A-Za-z0-9_.:-]+$"
    },
    "revision": {
      "type": "integer",
      "minimum": 1,
      "maximum": 9007199254740991
    },
    "basedOn": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "creationId": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            },
            "version": {
              "type": "integer",
              "minimum": 1,
              "maximum": 9007199254740991
            }
          },
          "required": [
            "creationId",
            "version"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "branch": {
      "type": "string",
      "enum": [
        "quantitative",
        "case-study"
      ]
    },
    "title": {
      "type": "string",
      "maxLength": 240
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
    },
    "updatedAt": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
    },
    "nodes": {
      "minItems": 1,
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "pattern": "^[A-Za-z0-9_.:-]+$"
          },
          "kind": {
            "type": "string",
            "enum": [
              "question",
              "concept",
              "measure",
              "population",
              "design",
              "hypothesis",
              "analysis",
              "source",
              "review",
              "selection"
            ]
          },
          "title": {
            "type": "string",
            "maxLength": 240
          },
          "detail": {
            "type": "string",
            "maxLength": 8000
          },
          "role": {
            "type": "string",
            "enum": [
              "predictor",
              "outcome",
              "context",
              "case",
              "evidence"
            ]
          },
          "reviewState": {
            "type": "string",
            "enum": [
              "open",
              "affected",
              "checked"
            ]
          },
          "position": {
            "type": "object",
            "properties": {
              "x": {
                "type": "number"
              },
              "y": {
                "type": "number"
              }
            },
            "required": [
              "x",
              "y"
            ],
            "additionalProperties": false
          },
          "fields": {
            "type": "object",
            "propertyNames": {
              "type": "string",
              "maxLength": 80
            },
            "additionalProperties": {
              "type": "string",
              "maxLength": 4000
            }
          },
          "sourceRef": {
            "type": "object",
            "properties": {
              "libraryId": {
                "type": "string",
                "minLength": 1,
                "maxLength": 120,
                "pattern": "^[A-Za-z0-9_.:-]+$"
              },
              "objectVersion": {
                "anyOf": [
                  {
                    "type": "string",
                    "maxLength": 120
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "fingerprint": {
                "type": "string",
                "pattern": "^sha256:[a-f0-9]{64}$"
              },
              "rights": {
                "type": "string",
                "enum": [
                  "available",
                  "held"
                ]
              }
            },
            "required": [
              "libraryId",
              "objectVersion",
              "fingerprint",
              "rights"
            ],
            "additionalProperties": false
          }
        },
        "required": [
          "id",
          "kind",
          "title",
          "detail",
          "reviewState",
          "position",
          "fields"
        ],
        "additionalProperties": false
      }
    },
    "connections": {
      "maxItems": 300,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "pattern": "^[A-Za-z0-9_.:-]+$"
          },
          "source": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "pattern": "^[A-Za-z0-9_.:-]+$"
          },
          "target": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "pattern": "^[A-Za-z0-9_.:-]+$"
          },
          "kind": {
            "type": "string",
            "enum": [
              "asks-about",
              "operationalizes",
              "applies-to",
              "uses-design",
              "tests",
              "analysed-by",
              "supported-by",
              "requires-review",
              "bounds-case",
              "collects-evidence",
              "informs-interpretation",
              "feeds"
            ]
          }
        },
        "required": [
          "id",
          "source",
          "target",
          "kind"
        ],
        "additionalProperties": false
      }
    },
    "checks": {
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "pattern": "^[A-Za-z0-9_.:-]+$"
          },
          "label": {
            "type": "string",
            "maxLength": 240
          },
          "state": {
            "type": "string",
            "enum": [
              "open",
              "checked",
              "affected"
            ]
          },
          "nodeIds": {
            "maxItems": 40,
            "type": "array",
            "items": {
              "type": "string",
              "minLength": 1,
              "maxLength": 120,
              "pattern": "^[A-Za-z0-9_.:-]+$"
            }
          },
          "checkedAt": {
            "anyOf": [
              {
                "type": "string",
                "format": "date-time",
                "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
              },
              {
                "type": "null"
              }
            ]
          },
          "note": {
            "type": "string",
            "maxLength": 2000
          }
        },
        "required": [
          "id",
          "label",
          "state",
          "nodeIds",
          "checkedAt",
          "note"
        ],
        "additionalProperties": false
      }
    },
    "serviceReceipts": {
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1,
            "maxLength": 120,
            "pattern": "^[A-Za-z0-9_.:-]+$"
          },
          "service": {
            "type": "string",
            "enum": [
              "research-methods.recommend-design",
              "research-methods.power",
              "research-methods.power-cluster",
              "research-methods.regression",
              "research-methods.mixed"
            ]
          },
          "contractVersion": {
            "type": "string",
            "pattern": "^\\d+\\.\\d+\\.\\d+$"
          },
          "inputHash": {
            "type": "string",
            "pattern": "^sha256:[a-f0-9]{64}$"
          },
          "requestedAt": {
            "type": "string",
            "format": "date-time",
            "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
          },
          "state": {
            "type": "string",
            "enum": [
              "accepted-suggestion",
              "suggestion",
              "stale",
              "refused"
            ]
          },
          "reasons": {
            "maxItems": 20,
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 1000
            }
          },
          "sourceQualifiers": {
            "maxItems": 20,
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 1000
            }
          }
        },
        "required": [
          "id",
          "service",
          "contractVersion",
          "inputHash",
          "requestedAt",
          "state",
          "reasons",
          "sourceQualifiers"
        ],
        "additionalProperties": false
      }
    },
    "viewport": {
      "type": "object",
      "properties": {
        "x": {
          "type": "number"
        },
        "y": {
          "type": "number"
        },
        "zoom": {
          "type": "number",
          "minimum": 0.2,
          "maximum": 2
        }
      },
      "required": [
        "x",
        "y",
        "zoom"
      ],
      "additionalProperties": false
    },
    "selection": {
      "type": "object",
      "properties": {
        "schema": {
          "type": "string",
          "const": "toolbox.study-selection-workspace/1"
        },
        "frame": {
          "type": "object",
          "properties": {
            "version": {
              "type": "string",
              "minLength": 1,
              "maxLength": 64,
              "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
            },
            "unit": {
              "type": "string",
              "enum": [
                "person",
                "team",
                "site",
                "case"
              ]
            },
            "rows": {
              "minItems": 1,
              "maxItems": 500,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
                  },
                  "values": {
                    "type": "object",
                    "propertyNames": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{0,39}$"
                    },
                    "additionalProperties": {
                      "anyOf": [
                        {
                          "type": "string",
                          "maxLength": 1000
                        },
                        {
                          "type": "number"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  }
                },
                "required": [
                  "id",
                  "values"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "version",
            "unit",
            "rows"
          ],
          "additionalProperties": false
        },
        "steps": {
          "maxItems": 12,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string",
                "minLength": 1,
                "maxLength": 64,
                "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
              },
              "parentId": {
                "anyOf": [
                  {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "result": {
                "type": "object",
                "properties": {
                  "schema": {
                    "type": "string",
                    "const": "toolbox.study-selection-result/1"
                  },
                  "contractVersion": {
                    "type": "string",
                    "const": "1.0.0"
                  },
                  "operation": {
                    "type": "string",
                    "enum": [
                      "segment",
                      "stratify",
                      "sample",
                      "pair"
                    ]
                  },
                  "runId": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
                  },
                  "inputVersion": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 64,
                    "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
                  },
                  "inputHash": {
                    "type": "string",
                    "pattern": "^sha256:[a-f0-9]{64}$"
                  },
                  "computedAt": {
                    "type": "string",
                    "format": "date-time",
                    "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
                  },
                  "settings": {
                    "oneOf": [
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "segment"
                          },
                          "source": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9_]{0,39}$"
                          },
                          "target": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9_]{0,39}$"
                          },
                          "mapping": {
                            "minItems": 1,
                            "maxItems": 100,
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "from": {
                                  "type": "string",
                                  "maxLength": 160
                                },
                                "to": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 100
                                }
                              },
                              "required": [
                                "from",
                                "to"
                              ],
                              "additionalProperties": false
                            }
                          },
                          "unmapped": {
                            "type": "string",
                            "enum": [
                              "keep",
                              "separate",
                              "refuse"
                            ]
                          }
                        },
                        "required": [
                          "kind",
                          "source",
                          "target",
                          "mapping",
                          "unmapped"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "stratify"
                          },
                          "categories": {
                            "maxItems": 3,
                            "type": "array",
                            "items": {
                              "type": "string",
                              "pattern": "^[a-z][a-z0-9_]{0,39}$"
                            }
                          },
                          "numericField": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^[a-z][a-z0-9_]{0,39}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "cuts": {
                            "maxItems": 12,
                            "type": "array",
                            "items": {
                              "type": "number"
                            }
                          },
                          "target": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9_]{0,39}$"
                          }
                        },
                        "required": [
                          "kind",
                          "categories",
                          "numericField",
                          "cuts",
                          "target"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "sample"
                          },
                          "method": {
                            "type": "string",
                            "enum": [
                              "simple_random",
                              "stratified",
                              "systematic",
                              "census"
                            ]
                          },
                          "n": {
                            "type": "integer",
                            "minimum": 1,
                            "maximum": 500
                          },
                          "seed": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 2147483647
                          },
                          "stratumField": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^[a-z][a-z0-9_]{0,39}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "replacement": {
                            "type": "boolean",
                            "const": false
                          }
                        },
                        "required": [
                          "kind",
                          "method",
                          "n",
                          "seed",
                          "stratumField",
                          "replacement"
                        ],
                        "additionalProperties": false
                      },
                      {
                        "type": "object",
                        "properties": {
                          "kind": {
                            "type": "string",
                            "const": "pair"
                          },
                          "mode": {
                            "type": "string",
                            "enum": [
                              "match-controls",
                              "randomize-pairs"
                            ]
                          },
                          "scoreField": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9_]{0,39}$"
                          },
                          "stratumField": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^[a-z][a-z0-9_]{0,39}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "maxDistance": {
                            "type": "number",
                            "minimum": 0
                          },
                          "seed": {
                            "type": "integer",
                            "minimum": 0,
                            "maximum": 2147483647
                          },
                          "armField": {
                            "anyOf": [
                              {
                                "type": "string",
                                "pattern": "^[a-z][a-z0-9_]{0,39}$"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          },
                          "treatment": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100
                          },
                          "control": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 100
                          }
                        },
                        "required": [
                          "kind",
                          "mode",
                          "scoreField",
                          "stratumField",
                          "maxDistance",
                          "seed",
                          "armField",
                          "treatment",
                          "control"
                        ],
                        "additionalProperties": false
                      }
                    ]
                  },
                  "method": {
                    "type": "string",
                    "maxLength": 240
                  },
                  "includedIds": {
                    "maxItems": 500,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 64,
                      "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
                    }
                  },
                  "changes": {
                    "maxItems": 500,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 64,
                          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
                        },
                        "values": {
                          "type": "object",
                          "propertyNames": {
                            "type": "string",
                            "pattern": "^[a-z][a-z0-9_]{0,39}$"
                          },
                          "additionalProperties": {
                            "anyOf": [
                              {
                                "type": "string",
                                "maxLength": 1000
                              },
                              {
                                "type": "number"
                              },
                              {
                                "type": "null"
                              }
                            ]
                          }
                        }
                      },
                      "required": [
                        "id",
                        "values"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "groups": {
                    "maxItems": 500,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "label": {
                          "type": "string",
                          "maxLength": 1000
                        },
                        "available": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        },
                        "selected": {
                          "type": "integer",
                          "minimum": 0,
                          "maximum": 9007199254740991
                        }
                      },
                      "required": [
                        "label",
                        "available",
                        "selected"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "unmatched": {
                    "maxItems": 500,
                    "type": "array",
                    "items": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 64,
                          "pattern": "^[A-Za-z0-9][A-Za-z0-9._:-]*$"
                        },
                        "reason": {
                          "type": "string",
                          "maxLength": 240
                        }
                      },
                      "required": [
                        "id",
                        "reason"
                      ],
                      "additionalProperties": false
                    }
                  },
                  "warnings": {
                    "maxItems": 20,
                    "type": "array",
                    "items": {
                      "type": "string",
                      "maxLength": 1000
                    }
                  },
                  "proof": {
                    "type": "string",
                    "pattern": "^[a-f0-9]{64}$"
                  }
                },
                "required": [
                  "schema",
                  "contractVersion",
                  "operation",
                  "runId",
                  "inputVersion",
                  "inputHash",
                  "computedAt",
                  "settings",
                  "method",
                  "includedIds",
                  "changes",
                  "groups",
                  "unmatched",
                  "warnings",
                  "proof"
                ],
                "additionalProperties": false
              }
            },
            "required": [
              "id",
              "parentId",
              "result"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [
        "schema",
        "frame",
        "steps"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "schema",
    "documentId",
    "revision",
    "basedOn",
    "branch",
    "title",
    "createdAt",
    "updatedAt",
    "nodes",
    "connections",
    "checks",
    "serviceReceipts",
    "viewport"
  ],
  "additionalProperties": false
}