{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://brainfile.md/v2/base.json",
  "title": "Brainfile Base Schema",
  "description": "Base schema that all brainfile types extend. Defines shared fields for board configuration files.",
  "type": "object",
  "required": ["title"],
  "properties": {
    "type": {
      "type": "string",
      "description": "Type identifier. Default: board.",
      "minLength": 1,
      "examples": ["board"]
    },
    "schema": {
      "type": "string",
      "description": "Schema URL for validation. Official types use brainfile.md/v2/{type}.json.",
      "examples": [
        "https://brainfile.md/v2/board.json"
      ]
    },
    "title": {
      "type": "string",
      "description": "Title of the brainfile",
      "minLength": 1,
      "examples": ["My Project", "Dev Log 2025", "Reading List"]
    },
    "protocolVersion": {
      "type": "string",
      "description": "Version of the Brainfile protocol this file uses",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$",
      "default": "2.0.0"
    },
    "agent": {
      "type": "object",
      "description": "Instructions for AI agents interacting with the brainfile",
      "properties": {
        "instructions": {
          "type": "array",
          "description": "List of instructions for AI agents",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "llmNotes": {
          "type": "string",
          "description": "Free-form notes about how this project prefers AI work to be structured"
        },
        "identity": {
          "type": "string",
          "description": "System prompt identity — who this agent is and how it should behave"
        },
        "tools": {
          "type": "object",
          "description": "CLI tools and commands available for agents to use",
          "additionalProperties": {
            "type": "object",
            "properties": {
              "description": {
                "type": "string"
              },
              "alias": {
                "type": "string"
              },
              "prefer": {
                "type": ["boolean", "string"]
              },
              "commands": {
                "type": "array",
                "items": {
                  "type": "string"
                }
              }
            },
            "additionalProperties": true
          }
        }
      },
      "additionalProperties": true
    },
    "rules": {
      "type": "object",
      "description": "Project rules organized by category",
      "properties": {
        "always": {
          "type": "array",
          "description": "Rules that must always be followed",
          "items": { "$ref": "#/definitions/rule" }
        },
        "never": {
          "type": "array",
          "description": "Rules that must never be violated",
          "items": { "$ref": "#/definitions/rule" }
        },
        "prefer": {
          "type": "array",
          "description": "Preferred approaches or patterns",
          "items": { "$ref": "#/definitions/rule" }
        },
        "context": {
          "type": "array",
          "description": "Contextual information and constraints",
          "items": { "$ref": "#/definitions/rule" }
        }
      },
      "additionalProperties": true
    }
  },
  "additionalProperties": true,
  "definitions": {
    "rule": {
      "type": "object",
      "required": ["id", "rule"],
      "properties": {
        "id": {
          "type": ["integer", "string"],
          "description": "Unique identifier within the rule category"
        },
        "rule": {
          "type": "string",
          "description": "The rule text",
          "minLength": 1
        }
      },
      "additionalProperties": true
    },
    "timestamp": {
      "type": "string",
      "description": "ISO 8601 timestamp",
      "format": "date-time",
      "examples": ["2026-01-15T10:30:00Z"]
    }
  }
}
