{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Read-only subagent stdio observability v1",
  "oneOf": [
    {
      "$ref": "#/$defs/command"
    },
    {
      "$ref": "#/$defs/response"
    },
    {
      "$ref": "#/$defs/event"
    }
  ],
  "$defs": {
    "command": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "version"
      ],
      "properties": {
        "type": {
          "const": "subagent_status"
        },
        "id": {
          "type": "string",
          "maxLength": 128,
          "pattern": "^[^\\r\\n]*$"
        },
        "version": {
          "const": 1
        }
      }
    },
    "response": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "command",
        "success",
        "data"
      ],
      "properties": {
        "type": {
          "const": "response"
        },
        "command": {
          "const": "subagent_status"
        },
        "id": {
          "type": "string"
        },
        "success": {
          "const": true
        },
        "data": {
          "$ref": "#/$defs/snapshot"
        }
      }
    },
    "event": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "version",
        "sessionId",
        "epoch",
        "revision",
        "snapshot"
      ],
      "properties": {
        "version": {
          "const": 1
        },
        "sessionId": {
          "type": [
            "string",
            "null"
          ]
        },
        "epoch": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "type": {
          "const": "subagent_event"
        },
        "revision": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "snapshot": {
          "$ref": "#/$defs/snapshot"
        }
      }
    },
    "snapshot": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "version",
        "sessionId",
        "epoch",
        "revision",
        "available",
        "capabilities",
        "fleet",
        "runs",
        "omitted"
      ],
      "properties": {
        "version": {
          "const": 1
        },
        "sessionId": {
          "type": [
            "string",
            "null"
          ]
        },
        "epoch": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "revision": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "available": {
          "type": "boolean"
        },
        "capabilities": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "snapshot",
            "events"
          ],
          "properties": {
            "snapshot": {
              "const": true
            },
            "events": {
              "type": "boolean"
            }
          }
        },
        "fleet": {
          "$ref": "#/$defs/fleet"
        },
        "runs": {
          "type": "array",
          "maxItems": 32,
          "items": {
            "$ref": "#/$defs/node"
          }
        },
        "omitted": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "runs",
            "children"
          ],
          "properties": {
            "runs": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "children": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          }
        }
      }
    },
    "fleet": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "version",
        "entries",
        "totalActive",
        "topLevelAsyncCapacity",
        "omitted"
      ],
      "properties": {
        "version": {
          "const": 1
        },
        "entries": {
          "type": "array",
          "maxItems": 16,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "key",
              "agent",
              "startedAt",
              "tokens"
            ],
            "properties": {
              "key": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128,
                "pattern": "^[^/\\\\\\r\\n]+$"
              },
              "agent": {
                "type": "string",
                "minLength": 1,
                "maxLength": 96
              },
              "role": {
                "type": "string",
                "minLength": 1,
                "maxLength": 96
              },
              "model": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              },
              "effort": {
                "type": "string",
                "minLength": 1,
                "maxLength": 128
              },
              "startedAt": {
                "type": "integer",
                "minimum": 0,
                "maximum": 9007199254740991
              },
              "tokens": {
                "$ref": "#/$defs/tokens"
              },
              "goal": {
                "type": "string",
                "minLength": 1,
                "maxLength": 512
              }
            }
          }
        },
        "totalActive": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "topLevelAsyncCapacity": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "used",
            "limit"
          ],
          "properties": {
            "used": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "limit": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            }
          }
        },
        "omitted": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      }
    },
    "node": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "key",
        "status",
        "children",
        "omittedChildren"
      ],
      "properties": {
        "key": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[^/\\\\\\r\\n]+$"
        },
        "runId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[^/\\\\\\r\\n]+$"
        },
        "workflowId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128,
          "pattern": "^[^/\\\\\\r\\n]+$"
        },
        "agent": {
          "type": "string",
          "minLength": 1,
          "maxLength": 96
        },
        "status": {
          "enum": [
            "queued",
            "pending",
            "running",
            "complete",
            "completed",
            "failed",
            "partial",
            "paused",
            "stopped",
            "rejected",
            "detached"
          ]
        },
        "activity": {
          "enum": [
            "waiting_supervisor",
            "needs_attention"
          ]
        },
        "startedAt": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "updatedAt": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "endedAt": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "progress": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "currentTool": {
          "type": "string",
          "minLength": 1,
          "maxLength": 96
        },
        "tokens": {
          "$ref": "#/$defs/tokens"
        },
        "error": {
          "type": "string",
          "minLength": 1,
          "maxLength": 256
        },
        "reason": {
          "type": "string",
          "minLength": 1,
          "maxLength": 128
        },
        "outcome": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "status"
          ],
          "properties": {
            "status": {
              "enum": [
                "queued",
                "pending",
                "running",
                "complete",
                "completed",
                "failed",
                "partial",
                "paused",
                "stopped",
                "rejected",
                "detached"
              ]
            },
            "success": {
              "type": "boolean"
            },
            "exitCode": {
              "type": "integer",
              "minimum": -9007199254740991,
              "maximum": 9007199254740991
            }
          }
        },
        "processTerminal": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "state"
          ],
          "properties": {
            "state": {
              "enum": [
                "pending",
                "observed",
                "unknown",
                "not-started"
              ]
            },
            "observedAt": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "reason": {
              "type": "string",
              "minLength": 1,
              "maxLength": 128
            }
          }
        },
        "children": {
          "type": "array",
          "maxItems": 16,
          "items": {
            "$ref": "#/$defs/node"
          }
        },
        "omittedChildren": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      }
    },
    "tokens": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "input",
        "output",
        "total"
      ],
      "properties": {
        "input": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "output": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "total": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "window": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "windowPeak": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      }
    }
  }
}
