{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Research workspace configuration 1.0",
  "$comment": "config.js additionally checks ID uniqueness within each collection, stage and agent references, and cycles in the stage dependency and agent parent graphs. The dashboard order must contain all three sections exactly once.",
  "type": "object",
  "description": "Describes a team's objective, stages, named agents, routines and dashboard preferences. Live evidence and execution permissions are maintained separately.",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "workspace",
    "stages",
    "agents",
    "routine",
    "dashboard",
    "reporting"
  ],
  "properties": {
    "schemaVersion": {
      "type": "string",
      "const": "1.0"
    },
    "workspaceId": {
      "type": "string",
      "minLength": 36,
      "maxLength": 36,
      "pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?![\\s\\S])",
      "description": "Optional persistent workspace UUID. A newly initialized local workspace generates one when it is absent."
    },
    "workspace": {
      "$ref": "#/$defs/workspace"
    },
    "stages": {
      "type": "array",
      "description": "Working order for the pipeline. A stage may depend on a later list entry.",
      "minItems": 1,
      "maxItems": 24,
      "items": {
        "$ref": "#/$defs/stage"
      }
    },
    "agents": {
      "type": "array",
      "description": "Named participants. Each instance has its own ID and may share its tool with any other participant.",
      "minItems": 1,
      "maxItems": 32,
      "items": {
        "$ref": "#/$defs/agent"
      }
    },
    "routine": {
      "$ref": "#/$defs/routine"
    },
    "dashboard": {
      "$ref": "#/$defs/dashboard"
    },
    "reporting": {
      "$ref": "#/$defs/reporting"
    },
    "researchIntent": {
      "type": "object",
      "description": "Verbatim research notes and the choices made during setup. These describe intent. Scientific conditions belong in the workspace and stages. The complete readable configuration export is limited to 256 KiB of UTF-8.",
      "additionalProperties": false,
      "required": [
        "notes",
        "confirmedChoices",
        "defaults",
        "unresolved"
      ],
      "properties": {
        "notes": {
          "type": "array",
          "minItems": 0,
          "maxItems": 8,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32000
          }
        },
        "confirmedChoices": {
          "type": "array",
          "minItems": 0,
          "maxItems": 128,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4096
          }
        },
        "defaults": {
          "type": "array",
          "minItems": 0,
          "maxItems": 128,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4096
          }
        },
        "unresolved": {
          "type": "array",
          "minItems": 0,
          "maxItems": 128,
          "items": {
            "type": "string",
            "minLength": 1,
            "maxLength": 4096
          }
        }
      }
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 40,
      "pattern": "^(?!(?:constructor|prototype)(?![\\s\\S]))[a-z][a-z0-9]*(?:-[a-z0-9]+)*(?![\\s\\S])",
      "description": "Use a lowercase letter first, then lowercase letters, digits or single hyphens between words. The names constructor and prototype are reserved."
    },
    "nullableId": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1,
      "maxLength": 40,
      "pattern": "^(?!(?:constructor|prototype)(?![\\s\\S]))[a-z][a-z0-9]*(?:-[a-z0-9]+)*(?![\\s\\S])",
      "description": "Use null for a top-level agent or the ID of its parent agent."
    },
    "label": {
      "type": "string",
      "description": "A short, single-line display label.",
      "minLength": 1,
      "maxLength": 64,
      "pattern": "^(?=[\\s\\S]*[^\\s\\uFEFF])[^\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029\\ud800-\\udfff]+(?![\\s\\S])"
    },
    "item": {
      "type": "string",
      "description": "A check or completion condition that a reviewer can verify. Use one line.",
      "minLength": 1,
      "maxLength": 160,
      "pattern": "^(?=[\\s\\S]*[^\\s\\uFEFF])[^\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029\\ud800-\\udfff]+(?![\\s\\S])"
    },
    "checks": {
      "type": "array",
      "description": "One to eight distinct checks.",
      "minItems": 1,
      "maxItems": 8,
      "uniqueItems": true,
      "items": {
        "$ref": "#/$defs/item"
      }
    },
    "workspace": {
      "type": "object",
      "description": "The shared objective and its completion criteria.",
      "additionalProperties": false,
      "required": [
        "name",
        "objective",
        "doneWhen",
        "environment"
      ],
      "properties": {
        "name": {
          "type": "string",
          "description": "The workspace title.",
          "minLength": 1,
          "maxLength": 80,
          "pattern": "^(?=[\\s\\S]*[^\\s\\uFEFF])[^\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029\\ud800-\\udfff]+(?![\\s\\S])"
        },
        "objective": {
          "type": "string",
          "description": "A finite research objective in one sentence.",
          "minLength": 1,
          "maxLength": 240,
          "pattern": "^(?=[\\s\\S]*[^\\s\\uFEFF])[^\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029\\ud800-\\udfff]+(?![\\s\\S])"
        },
        "doneWhen": {
          "$ref": "#/$defs/checks"
        },
        "environment": {
          "type": "string",
          "enum": [
            "slurm",
            "htcondor",
            "aws",
            "kubernetes",
            "local",
            "generic"
          ],
          "description": "The environment the team uses. Local and generic also support offline planning."
        }
      }
    },
    "stage": {
      "type": "object",
      "description": "A named pipeline stage with its immediate prerequisites.",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "kind",
        "dependsOn"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "name": {
          "$ref": "#/$defs/label"
        },
        "purpose": {
          "$ref": "#/$defs/item",
          "description": "Optional scientific purpose of this stage, retained independently of its display name."
        },
        "kind": {
          "type": "string",
          "enum": [
            "intake",
            "production",
            "aggregation",
            "validation",
            "custom"
          ],
          "description": "The role of this step. Use custom for a project-specific stage."
        },
        "dependsOn": {
          "type": "array",
          "description": "IDs of stages that must finish before this one. Use an empty list for an entry stage.",
          "minItems": 0,
          "maxItems": 23,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "outputs": {
          "type": "array",
          "description": "Optional expected deliverables of this stage. Labels describe the plan and convey no observed output or execution authority.",
          "minItems": 1,
          "maxItems": 8,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/item"
          }
        }
      }
    },
    "agent": {
      "type": "object",
      "description": "A named agent instance. Tools and display names are free text.",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "tool",
        "role",
        "stages",
        "parentId"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "name": {
          "$ref": "#/$defs/label"
        },
        "tool": {
          "$ref": "#/$defs/label"
        },
        "role": {
          "type": "string",
          "description": "The responsibility this particular agent holds.",
          "minLength": 1,
          "maxLength": 120,
          "pattern": "^(?=[\\s\\S]*[^\\s\\uFEFF])[^\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029\\ud800-\\udfff]+(?![\\s\\S])"
        },
        "stages": {
          "type": "array",
          "description": "Stage IDs this agent covers.",
          "minItems": 1,
          "maxItems": 24,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        },
        "parentId": {
          "$ref": "#/$defs/nullableId"
        }
      }
    },
    "routine": {
      "type": "object",
      "description": "How the team checks progress, reviews evidence and hands off work.",
      "additionalProperties": false,
      "required": [
        "heartbeatMinutes",
        "handoff",
        "recovery",
        "validation",
        "humanApproval"
      ],
      "properties": {
        "heartbeatMinutes": {
          "type": "integer",
          "minimum": 1,
          "maximum": 1440,
          "description": "Planned interval between progress checks in minutes."
        },
        "handoff": {
          "type": "string",
          "enum": [
            "evidence-first",
            "shift-note"
          ],
          "description": "How the incoming owner receives the work."
        },
        "recovery": {
          "type": "string",
          "enum": [
            "inspect-first",
            "pause-for-review"
          ],
          "description": "The review routine for an interrupted job."
        },
        "validation": {
          "$ref": "#/$defs/checks"
        },
        "humanApproval": {
          "type": "array",
          "description": "Actions to flag in the workspace. The list conveys no permission to act.",
          "minItems": 0,
          "maxItems": 3,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": [
              "retry",
              "merge",
              "publish"
            ],
            "description": "An action to flag for human review."
          }
        },
        "decisionOwner": {
          "type": "string",
          "description": "The person or group to ask when a human judgment is open. This label grants no authority.",
          "minLength": 1,
          "maxLength": 120,
          "pattern": "^(?=[\\s\\S]*[^\\s\\uFEFF])[^\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029\\ud800-\\udfff]+(?![\\s\\S])"
        }
      }
    },
    "dashboard": {
      "type": "object",
      "description": "Order, color and spacing of the home dashboard.",
      "additionalProperties": false,
      "required": [
        "order",
        "theme",
        "density"
      ],
      "properties": {
        "order": {
          "type": "array",
          "description": "Each of pipeline, agents and evidence appears exactly once, in display order.",
          "minItems": 3,
          "maxItems": 3,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "enum": [
              "pipeline",
              "agents",
              "evidence"
            ],
            "description": "A home dashboard section."
          }
        },
        "theme": {
          "type": "string",
          "enum": [
            "forest",
            "night",
            "paper"
          ],
          "description": "Dashboard color theme."
        },
        "density": {
          "type": "string",
          "enum": [
            "compact",
            "comfortable"
          ],
          "description": "Dashboard spacing."
        }
      }
    },
    "reporting": {
      "type": "object",
      "description": "How often the team expects to hear from its agents and in what form.",
      "additionalProperties": false,
      "required": [
        "cadence",
        "style"
      ],
      "properties": {
        "cadence": {
          "type": "string",
          "enum": [
            "on-handoff",
            "daily",
            "on-change"
          ],
          "description": "When the team expects a report."
        },
        "style": {
          "type": "string",
          "enum": [
            "brief",
            "detailed"
          ],
          "description": "The level of detail in a report."
        }
      }
    }
  }
}
