{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/mmerterden/multi-agent-pipeline/pipeline/schemas/learnings-ledger.schema.json",
  "version": "1.0.0",
  "title": "Multi-Agent Pipeline  -  persistent learnings ledger row",
  "description": "One durable knowledge entry, append-only, one file per repo at $HOME/.claude/memory/multi-agent/<repo-slug>/learnings-ledger.jsonl. Distinct from triage-corpus (per-task findings): the ledger holds knowledge replayed into EVERY future run of the same repo - architectural facts, conventions, and explicitly rejected review preferences - so agents stop re-discovering structure and reviewers stop re-flagging rejected feedback.",
  "type": "object",
  "additionalProperties": false,
  "required": ["v", "ts", "repo_slug", "kind", "scope", "statement"],
  "properties": {
    "v": { "type": "string", "description": "Row schema version." },
    "ts": {
      "type": "string",
      "format": "date-time",
      "description": "When the entry was recorded."
    },
    "repo_slug": {
      "type": "string",
      "minLength": 1,
      "description": "Repo the knowledge belongs to."
    },
    "kind": {
      "type": "string",
      "enum": ["fact", "convention", "rejected-preference"],
      "description": "fact = architectural truth ('auth tokens go through KeychainStore'); convention = a project rule; rejected-preference = a review suggestion the team explicitly rejected, so reviewers should not re-raise it."
    },
    "scope": {
      "type": "string",
      "minLength": 1,
      "description": "Path glob the entry applies to (e.g. 'Auth/*'), or 'global'."
    },
    "statement": {
      "type": "string",
      "minLength": 1,
      "description": "The knowledge itself, in one line."
    },
    "source_task": {
      "type": ["string", "null"],
      "description": "Task id that produced this entry, or null when added manually."
    },
    "confidence": {
      "type": "string",
      "enum": ["low", "medium", "high"],
      "description": "How strongly to weight the entry when replaying it."
    },
    "diagnosis": {
      "type": "string",
      "description": "Optional causal 'why' behind the lesson (Reflexion): the root-cause reasoning that turns a detected failure into a prevented one. Rendered in the brief as '(why: ...)'. Absent for plain facts/conventions."
    }
  }
}
