{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Tracefolio shared human/AI report contract v2",
  "type": "object",
  "required": [
    "schemaVersion",
    "project",
    "kind",
    "title",
    "summary",
    "outcome"
  ],
  "properties": {
    "schemaVersion": {
      "const": 2
    },
    "project": {
      "enum": [
        "codex-config",
        "affinity-cli",
        "pixora",
        "designdatatable",
        "enginemigrator",
        "codeassist",
        "windowsfoldersize",
        "turnroom",
        "moa",
        "last37n",
        "pixelcamera"
      ]
    },
    "kind": {
      "enum": [
        "result",
        "bug",
        "discussion",
        "manual"
      ]
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 180
    },
    "summary": {
      "type": "string",
      "minLength": 1,
      "maxLength": 180
    },
    "outcome": {
      "type": "string",
      "minLength": 1,
      "maxLength": 5000
    },
    "workflow": {
      "enum": [
        "new",
        "review",
        "in_progress",
        "resolved",
        "closed"
      ]
    },
    "priority": {
      "enum": [
        "low",
        "normal",
        "high",
        "urgent"
      ]
    },
    "severity": {
      "enum": [
        "minor",
        "normal",
        "major",
        "critical"
      ]
    },
    "state": {
      "enum": [
        "complete",
        "partial",
        "progress",
        "verification",
        "blocked"
      ]
    },
    "reporter": {
      "type": "string",
      "maxLength": 5000
    },
    "assignee": {
      "type": "string",
      "maxLength": 5000
    },
    "environment": {
      "type": "string",
      "maxLength": 5000
    },
    "steps": {
      "type": "string",
      "maxLength": 5000
    },
    "expected": {
      "type": "string",
      "maxLength": 5000
    },
    "actual": {
      "type": "string",
      "maxLength": 5000
    },
    "cause": {
      "type": "string",
      "maxLength": 5000
    },
    "changes": {
      "type": "string",
      "maxLength": 5000
    },
    "verification": {
      "type": "string",
      "maxLength": 5000
    },
    "remaining": {
      "type": "string",
      "maxLength": 5000
    },
    "proposedTime": {
      "type": "string",
      "maxLength": 5000
    },
    "actualTime": {
      "type": "string",
      "maxLength": 5000
    },
    "xerjEvidence": {
      "type": "string",
      "maxLength": 5000
    },
    "topic": {
      "enum": [
        "qa",
        "gap",
        "proposal",
        "feature"
      ]
    },
    "discussionState": {
      "enum": [
        "open",
        "considering",
        "accepted",
        "deferred",
        "implemented"
      ]
    },
    "relatedReport": {
      "type": "string",
      "maxLength": 5000
    },
    "replyTo": {
      "type": "string",
      "maxLength": 5000
    },
    "decision": {
      "type": "string",
      "maxLength": 5000
    },
    "manualId": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9-]*$",
      "maxLength": 64
    },
    "round": {
      "type": "integer",
      "minimum": 1
    },
    "phase": {
      "enum": [
        "initial",
        "followup"
      ]
    },
    "manualState": {
      "enum": [
        "planned",
        "active",
        "qa",
        "blocked",
        "complete"
      ]
    },
    "tasks": {
      "type": "array",
      "minItems": 1,
      "maxItems": 30,
      "items": {
        "type": "object",
        "required": [
          "id",
          "title",
          "action",
          "expected",
          "qa",
          "revision",
          "status",
          "dependsOn"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^T[0-9]{2,3}$"
          },
          "status": {
            "enum": [
              "pending",
              "doing",
              "qa",
              "blocked",
              "done"
            ]
          },
          "revision": {
            "type": "integer",
            "minimum": 1
          },
          "visualEvidence": {
            "type": "array",
            "maxItems": 8,
            "items": {
              "type": "object",
              "required": [
                "role",
                "image",
                "caption"
              ],
              "additionalProperties": false,
              "properties": {
                "role": {
                  "enum": [
                    "reference",
                    "current"
                  ]
                },
                "image": {
                  "type": "string",
                  "pattern": "^\\.\\./assets/[a-zA-Z0-9_/-]+\\.(png|webp|jpg|jpeg|gif)$"
                },
                "caption": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 700
                },
                "source": {
                  "type": "string",
                  "format": "uri",
                  "pattern": "^https://"
                }
              }
            }
          }
        }
      }
    },
    "focusTasks": {
      "type": "array",
      "minItems": 1,
      "maxItems": 30,
      "uniqueItems": true,
      "items": {
        "type": "string"
      }
    },
    "qaRuns": {
      "type": "array",
      "maxItems": 100
    },
    "previousManual": {
      "type": "string"
    },
    "relatedDiscussions": {
      "type": "array",
      "maxItems": 30
    },
    "scopeChange": {
      "type": "string"
    },
    "goal": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1500
    },
    "completionCriteria": {
      "type": "string",
      "minLength": 1,
      "maxLength": 1500
    },
    "testCases": {
      "type": "array",
      "minItems": 1,
      "maxItems": 60,
      "items": {
        "type": "object",
        "required": [
          "id",
          "group",
          "title",
          "steps",
          "expected",
          "actual",
          "status"
        ],
        "properties": {
          "id": {
            "type": "string",
            "pattern": "^[A-Z][A-Z0-9_-]{1,30}$"
          },
          "group": {
            "type": "string",
            "maxLength": 1200
          },
          "title": {
            "type": "string",
            "maxLength": 1200
          },
          "steps": {
            "type": "string",
            "maxLength": 1200
          },
          "expected": {
            "type": "string",
            "maxLength": 1200
          },
          "actual": {
            "type": "string",
            "maxLength": 1200
          },
          "fix": {
            "type": "string",
            "maxLength": 1200
          },
          "retest": {
            "type": "string",
            "maxLength": 1200
          },
          "reference": {
            "type": "string",
            "maxLength": 1200
          },
          "referenceImage": {
            "type": "string",
            "maxLength": 1200
          },
          "beforeImage": {
            "type": "string",
            "maxLength": 1200
          },
          "afterImage": {
            "type": "string",
            "maxLength": 1200
          },
          "missingEvidence": {
            "type": "string",
            "maxLength": 1200
          },
          "status": {
            "enum": [
              "pass",
              "fail",
              "partial",
              "not_run"
            ]
          }
        },
        "additionalProperties": false
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "kind": {
            "const": "bug"
          }
        }
      },
      "then": {
        "required": [
          "environment",
          "steps",
          "expected",
          "actual"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "bug"
          },
          "workflow": {
            "enum": [
              "resolved",
              "closed"
            ]
          }
        },
        "required": [
          "workflow"
        ]
      },
      "then": {
        "required": [
          "changes",
          "verification"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "discussion"
          }
        },
        "required": [
          "kind"
        ]
      },
      "then": {
        "required": [
          "topic",
          "discussionState"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "manual"
          }
        }
      },
      "then": {
        "required": [
          "manualId",
          "round",
          "phase",
          "manualState",
          "goal",
          "completionCriteria",
          "tasks",
          "focusTasks",
          "qaRuns"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "kind": {
            "const": "manual"
          },
          "phase": {
            "const": "followup"
          }
        },
        "required": [
          "phase"
        ]
      },
      "then": {
        "required": [
          "previousManual"
        ],
        "properties": {
          "round": {
            "minimum": 2
          },
          "focusTasks": {
            "maxItems": 5
          }
        }
      }
    },
    {
      "if": {
        "required": [
          "testCases"
        ]
      },
      "then": {
        "properties": {
          "kind": {
            "const": "result"
          }
        }
      }
    }
  ]
}
