{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/office-archive.schema.json",
  "title": "Memory archive",
  "description": "What GET /v1/archive returns and `office-archive.mjs --json` prints: per repository, the newest decisions with their rationale, security notes and learnings from the learnings ledger (entries their feedback retired, and entries a later entry superseded, are left out and counted apart), and the hubs, clusters, surprising connections and questions of the code graph report when one exists. Learnings promoted across repositories sit apart under `global`. Every text is redacted and cut short. Local only: it never leaves this machine.",
  "type": "object",
  "additionalProperties": false,
  "required": ["contractVersion", "generatedAt", "repos"],
  "$defs": {
    "count": {
      "type": "integer",
      "minimum": 0
    },
    "text": {
      "type": "string",
      "maxLength": 240
    },
    "cell": {
      "type": "string",
      "maxLength": 160
    },
    "at": {
      "type": ["string", "null"]
    },
    "scope": {
      "type": ["string", "null"],
      "maxLength": 120
    },
    "entry": {
      "type": "object",
      "additionalProperties": false,
      "required": ["statement", "scope", "at"],
      "properties": {
        "statement": {
          "$ref": "#/$defs/text"
        },
        "scope": {
          "$ref": "#/$defs/scope"
        },
        "at": {
          "$ref": "#/$defs/at"
        }
      }
    },
    "shelf": {
      "type": "object",
      "additionalProperties": false,
      "required": ["repo", "counts", "decisions", "securityNotes", "learnings", "graph"],
      "properties": {
        "repo": {
          "type": "string"
        },
        "counts": {
          "type": "object",
          "additionalProperties": false,
          "required": ["decisions", "securityNotes", "learnings", "retired", "superseded"],
          "properties": {
            "decisions": {
              "$ref": "#/$defs/count"
            },
            "securityNotes": {
              "$ref": "#/$defs/count"
            },
            "learnings": {
              "$ref": "#/$defs/count"
            },
            "retired": {
              "$ref": "#/$defs/count",
              "description": "Entries left out because their feedback retired them."
            },
            "superseded": {
              "$ref": "#/$defs/count",
              "description": "Entries left out because a later entry names them in its supersedes list. An entry both retired and superseded counts as retired."
            }
          }
        },
        "decisions": {
          "type": "array",
          "maxItems": 8,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["statement", "scope", "at", "rationale", "confidence"],
            "properties": {
              "statement": {
                "$ref": "#/$defs/text"
              },
              "scope": {
                "$ref": "#/$defs/scope"
              },
              "at": {
                "$ref": "#/$defs/at"
              },
              "rationale": {
                "type": ["string", "null"],
                "maxLength": 240
              },
              "confidence": {
                "enum": ["low", "medium", "high", null]
              }
            }
          }
        },
        "securityNotes": {
          "type": "array",
          "maxItems": 8,
          "items": {
            "$ref": "#/$defs/entry"
          }
        },
        "learnings": {
          "type": "array",
          "maxItems": 8,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["kind", "statement", "scope", "at"],
            "properties": {
              "kind": {
                "enum": ["fact", "convention", "rejected-preference"]
              },
              "statement": {
                "$ref": "#/$defs/text"
              },
              "scope": {
                "$ref": "#/$defs/scope"
              },
              "at": {
                "$ref": "#/$defs/at"
              }
            }
          }
        },
        "graph": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "additionalProperties": false,
              "required": ["builtAt", "hubs", "clusters", "surprising", "questions"],
              "properties": {
                "builtAt": {
                  "$ref": "#/$defs/at"
                },
                "hubs": {
                  "type": "array",
                  "maxItems": 8,
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": ["name", "kind", "degree", "path"],
                    "properties": {
                      "name": {
                        "$ref": "#/$defs/cell"
                      },
                      "kind": {
                        "$ref": "#/$defs/cell"
                      },
                      "degree": {
                        "type": "number",
                        "minimum": 0
                      },
                      "path": {
                        "$ref": "#/$defs/cell"
                      }
                    }
                  }
                },
                "clusters": {
                  "type": "array",
                  "maxItems": 8,
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": ["files", "cohesion", "around", "where"],
                    "properties": {
                      "files": {
                        "type": "number",
                        "minimum": 0
                      },
                      "cohesion": {
                        "type": "number"
                      },
                      "around": {
                        "$ref": "#/$defs/cell"
                      },
                      "where": {
                        "$ref": "#/$defs/cell"
                      }
                    }
                  }
                },
                "surprising": {
                  "type": "array",
                  "maxItems": 8,
                  "items": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": ["from", "to", "kind", "links"],
                    "properties": {
                      "from": {
                        "$ref": "#/$defs/cell"
                      },
                      "to": {
                        "$ref": "#/$defs/cell"
                      },
                      "kind": {
                        "$ref": "#/$defs/cell"
                      },
                      "links": {
                        "type": "number",
                        "minimum": 0
                      }
                    }
                  }
                },
                "questions": {
                  "type": "array",
                  "maxItems": 8,
                  "items": {
                    "$ref": "#/$defs/cell"
                  }
                }
              }
            }
          ]
        }
      }
    }
  },
  "properties": {
    "contractVersion": {
      "type": "string",
      "pattern": "^1\\.[0-9]+\\.[0-9]+$",
      "x-sensitivity": "none"
    },
    "generatedAt": {
      "type": "string",
      "format": "date-time",
      "x-sensitivity": "none"
    },
    "repos": {
      "type": "array",
      "maxItems": 30,
      "x-sensitivity": "local",
      "items": {
        "$ref": "#/$defs/shelf"
      }
    },
    "global": {
      "description": "The global ledger (written only by learnings-ledger.mjs promote --accept) on a shelf of its own, in the same shape as a repository's with `repo` set to `_global` and `graph` null; null until a learning has been promoted. Never listed in `repos`.",
      "x-sensitivity": "local",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/shelf"
        }
      ]
    }
  }
}
