{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://harness-forge.dev/schemas/runtime/decision-record.schema.json",
  "title": "Decision record",
  "$ref": "#/$defs/decisionRecord",
  "$defs": {
    "architectureSignificance": {
      "type": "string",
      "enum": ["low", "medium", "high", "critical"]
    },
    "reviewStatus": {
      "type": "string",
      "enum": ["draft", "inferred", "confirmed", "approved", "stale", "superseded"]
    },
    "decisionStatus": {
      "type": "string",
      "enum": ["proposed", "accepted", "rejected", "deferred", "superseded"]
    },
    "decisionRecordBase": {
      "type": "object",
      "required": [
        "id",
        "recordType",
        "title",
        "status",
        "reviewStatus",
        "architectureSignificance",
        "taskRefs",
        "createdAt",
        "updatedAt"
      ],
      "properties": {
        "id": { "type": "string" },
        "recordType": {
          "type": "string",
          "enum": ["asr", "adr"]
        },
        "title": { "type": "string" },
        "status": { "$ref": "#/$defs/decisionStatus" },
        "reviewStatus": { "$ref": "#/$defs/reviewStatus" },
        "architectureSignificance": { "$ref": "#/$defs/architectureSignificance" },
        "taskRefs": {
          "type": "array",
          "items": { "type": "string" }
        },
        "requirementRefs": {
          "type": "array",
          "items": { "type": "string" }
        },
        "fileInterestRef": { "type": "string" },
        "impactAnalysisRef": { "type": "string" },
        "templateId": { "type": "string" },
        "owner": { "type": "string" },
        "approver": { "type": "string" },
        "provenance": {
          "type": "array",
          "items": { "type": "string" }
        },
        "tags": {
          "type": "array",
          "items": { "type": "string" }
        },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "asrRecord": {
      "unevaluatedProperties": false,
      "allOf": [
        { "$ref": "#/$defs/decisionRecordBase" },
        {
          "type": "object",
          "required": [
            "summary",
            "problemStatement",
            "drivers",
            "qualityAttributes",
            "constraints",
            "affectedModules",
            "affectedFiles",
            "risks",
            "openQuestions",
            "optionsToEvaluate",
            "promotionCriteria"
          ],
          "properties": {
            "recordType": { "const": "asr" },
            "summary": { "type": "string" },
            "problemStatement": { "type": "string" },
            "drivers": {
              "type": "array",
              "items": { "type": "string" }
            },
            "qualityAttributes": {
              "type": "array",
              "items": { "type": "string" }
            },
            "constraints": {
              "type": "array",
              "items": { "type": "string" }
            },
            "affectedModules": {
              "type": "array",
              "items": { "type": "string" }
            },
            "affectedFiles": {
              "type": "array",
              "items": { "type": "string" }
            },
            "risks": {
              "type": "array",
              "items": { "type": "string" }
            },
            "openQuestions": {
              "type": "array",
              "items": { "type": "string" }
            },
            "optionsToEvaluate": {
              "type": "array",
              "items": { "type": "string" }
            },
            "promotionCriteria": {
              "type": "array",
              "items": { "type": "string" }
            }
          }
        }
      ]
    },
    "adrRecord": {
      "unevaluatedProperties": false,
      "allOf": [
        { "$ref": "#/$defs/decisionRecordBase" },
        {
          "type": "object",
          "required": [
            "asrRef",
            "decisionSummary",
            "context",
            "optionsConsidered",
            "decision",
            "consequences",
            "validationPlan",
            "rolloutPlan",
            "risksAndMitigations",
            "followUps",
            "supersedes",
            "supersededBy"
          ],
          "properties": {
            "recordType": { "const": "adr" },
            "asrRef": { "type": "string" },
            "decisionSummary": { "type": "string" },
            "context": { "type": "string" },
            "optionsConsidered": {
              "type": "array",
              "items": { "type": "string" }
            },
            "decision": { "type": "string" },
            "consequences": {
              "type": "array",
              "items": { "type": "string" }
            },
            "validationPlan": {
              "type": "array",
              "items": { "type": "string" }
            },
            "rolloutPlan": {
              "type": "array",
              "items": { "type": "string" }
            },
            "risksAndMitigations": {
              "type": "array",
              "items": { "type": "string" }
            },
            "followUps": {
              "type": "array",
              "items": { "type": "string" }
            },
            "supersedes": {
              "type": "array",
              "items": { "type": "string" }
            },
            "supersededBy": {
              "type": "array",
              "items": { "type": "string" }
            }
          }
        }
      ]
    },
    "decisionRecord": {
      "oneOf": [
        { "$ref": "#/$defs/asrRecord" },
        { "$ref": "#/$defs/adrRecord" }
      ]
    },
    "decisionIndexEntry": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "recordType",
        "path",
        "title",
        "status",
        "architectureSignificance",
        "taskRefs",
        "supersedes",
        "supersededBy",
        "reviewStatus",
        "createdAt",
        "updatedAt"
      ],
      "properties": {
        "id": { "type": "string" },
        "recordType": {
          "type": "string",
          "enum": ["asr", "adr"]
        },
        "path": { "type": "string" },
        "title": { "type": "string" },
        "status": { "$ref": "#/$defs/decisionStatus" },
        "architectureSignificance": { "$ref": "#/$defs/architectureSignificance" },
        "taskRefs": {
          "type": "array",
          "items": { "type": "string" }
        },
        "supersedes": {
          "type": "array",
          "items": { "type": "string" }
        },
        "supersededBy": {
          "type": "array",
          "items": { "type": "string" }
        },
        "reviewStatus": { "$ref": "#/$defs/reviewStatus" },
        "createdAt": {
          "type": "string",
          "format": "date-time"
        },
        "updatedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "decisionHealthFinding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "category", "severity", "title", "rationale", "evidence", "recommendedAction", "detectedAt"],
      "properties": {
        "id": { "type": "string" },
        "category": {
          "type": "string",
          "enum": [
            "timestamp-quality",
            "stale-decision",
            "unresolved-decision",
            "broken-lineage",
            "circular-lineage",
            "conflicting-lineage",
            "stale-reference",
            "coverage-gap"
          ]
        },
        "severity": {
          "type": "string",
          "enum": ["info", "warning", "blocker"]
        },
        "decisionId": { "type": "string" },
        "taskId": { "type": "string" },
        "title": { "type": "string" },
        "rationale": { "type": "string" },
        "evidence": {
          "type": "array",
          "items": { "type": "string" }
        },
        "recommendedAction": { "type": "string" },
        "detectedAt": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "decisionChain": {
      "type": "object",
      "additionalProperties": false,
      "required": ["chainId", "decisionIds", "status", "findings"],
      "properties": {
        "chainId": { "type": "string" },
        "decisionIds": {
          "type": "array",
          "items": { "type": "string" }
        },
        "currentDecisionId": { "type": "string" },
        "status": {
          "type": "string",
          "enum": ["complete", "broken", "circular", "branching", "conflicting"]
        },
        "findings": {
          "type": "array",
          "items": { "$ref": "#/$defs/decisionHealthFinding" }
        }
      }
    },
    "noDecisionRationale": {
      "type": "object",
      "additionalProperties": false,
      "required": ["taskId", "rationale", "recordedAt", "recordedBy", "reviewStatus"],
      "properties": {
        "taskId": { "type": "string" },
        "rationale": { "type": "string" },
        "recordedAt": {
          "type": "string",
          "format": "date-time"
        },
        "recordedBy": { "type": "string" },
        "reviewStatus": { "$ref": "#/$defs/reviewStatus" }
      }
    },
    "decisionCoverageResult": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "taskId",
        "architectureSignificance",
        "classification",
        "decisionRefs",
        "severity",
        "rationale",
        "recommendedAction"
      ],
      "properties": {
        "taskId": { "type": "string" },
        "architectureSignificance": { "$ref": "#/$defs/architectureSignificance" },
        "classification": {
          "type": "string",
          "enum": ["covered", "intentionally-uncovered", "missing-coverage", "not-required", "broken-reference", "stale-reference"]
        },
        "decisionRefs": {
          "type": "array",
          "items": { "type": "string" }
        },
        "noDecisionRationale": { "$ref": "#/$defs/noDecisionRationale" },
        "severity": {
          "type": "string",
          "enum": ["info", "warning", "blocker"]
        },
        "rationale": { "type": "string" },
        "recommendedAction": { "type": "string" }
      }
    },
    "decisionLog": {
      "type": "object",
      "additionalProperties": false,
      "required": ["generatedAt", "grouping", "entries", "findings"],
      "properties": {
        "generatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "grouping": {
          "type": "string",
          "enum": ["time-period", "status", "significance"]
        },
        "entries": {
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "title",
              "recordType",
              "status",
              "architectureSignificance",
              "reviewStatus",
              "createdAt",
              "updatedAt",
              "taskRefs",
              "supersessionState"
            ],
            "properties": {
              "id": { "type": "string" },
              "title": { "type": "string" },
              "recordType": {
                "type": "string",
                "enum": ["asr", "adr"]
              },
              "status": { "$ref": "#/$defs/decisionStatus" },
              "architectureSignificance": { "$ref": "#/$defs/architectureSignificance" },
              "reviewStatus": { "$ref": "#/$defs/reviewStatus" },
              "createdAt": {
                "type": "string",
                "format": "date-time"
              },
              "updatedAt": {
                "type": "string",
                "format": "date-time"
              },
              "taskRefs": {
                "type": "array",
                "items": { "type": "string" }
              },
              "supersessionState": { "type": "string" },
              "summary": { "type": "string" }
            }
          }
        },
        "findings": {
          "type": "array",
          "items": { "$ref": "#/$defs/decisionHealthFinding" }
        }
      }
    },
    "architectureChangeFeedEntry": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "occurredAt", "eventType", "decisionIds", "taskIds", "summary", "evidence"],
      "properties": {
        "id": { "type": "string" },
        "occurredAt": {
          "type": "string",
          "format": "date-time"
        },
        "eventType": {
          "type": "string",
          "enum": [
            "decision-created",
            "decision-updated",
            "decision-status-changed",
            "task-linked",
            "impact-analysis-linked",
            "review-status-changed",
            "health-finding-created",
            "coverage-classified"
          ]
        },
        "decisionIds": {
          "type": "array",
          "items": { "type": "string" }
        },
        "taskIds": {
          "type": "array",
          "items": { "type": "string" }
        },
        "severity": {
          "type": "string",
          "enum": ["info", "warning", "blocker"]
        },
        "summary": { "type": "string" },
        "evidence": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "decisionIndex": {
      "type": "object",
      "additionalProperties": false,
      "required": ["version", "generatedAt", "entries"],
      "properties": {
        "version": { "type": "integer", "minimum": 1 },
        "generatedAt": {
          "type": "string",
          "format": "date-time"
        },
        "entries": {
          "type": "array",
          "items": { "$ref": "#/$defs/decisionIndexEntry" }
        }
      }
    }
  }
}
