{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:orbiplex:schema:sensorium-virt-guest-frame:v1",
  "title": "Sensorium Virt Guest Frame v1",
  "description": "Bounded generation-, plan-, image-, and boot-bound frame for the Workbench guest channel.",
  "type": "object",
  "additionalProperties": false,
  "x-dia-workflow": "project",
  "x-dia-status": "draft",
  "x-dia-basis": ["doc/project/40-proposals/071-sensorium-workbench.md"],
  "required": ["schema", "schema/v", "frame/kind", "environment/ref", "source/generation-ref", "plan/digest", "image/manifest-digest", "guest-agent/protocol-version", "guest/cid", "boot/nonce", "sequence", "deadline-at", "payload/length", "payload/digest"],
  "properties": {
    "schema": { "const": "sensorium-virt-guest-frame.v1" },
    "schema/v": { "const": 1 },
    "frame/kind": { "enum": ["handshake", "request", "chunk", "result", "error"] },
    "environment/ref": { "$ref": "#/$defs/ref" },
    "source/generation-ref": { "$ref": "#/$defs/ref" },
    "plan/digest": { "$ref": "#/$defs/digest" },
    "image/manifest-digest": { "$ref": "#/$defs/digest" },
    "guest-agent/protocol-version": { "const": 1 },
    "guest/cid": { "type": "integer", "minimum": 3, "maximum": 4294967295 },
    "boot/nonce": { "type": "string", "minLength": 32, "maxLength": 128, "pattern": "^[A-Za-z0-9_-]+$" },
    "operation/id": { "$ref": "#/$defs/ref" },
    "operation/kind": { "enum": ["spawn-process", "open-pty", "terminal-input", "terminal-resize", "terminal-signal", "file-snapshot", "file-read", "patch-stage", "artifact-export", "quiesce", "shutdown"] },
    "sequence": { "type": "integer", "minimum": 0 },
    "deadline-at": { "type": "string", "format": "date-time" },
    "chunk/index": { "type": "integer", "minimum": 0, "maximum": 65535 },
    "chunk/count": { "type": "integer", "minimum": 1, "maximum": 128 },
    "payload/length": { "type": "integer", "minimum": 0, "maximum": 1048576 },
    "payload/digest": { "$ref": "#/$defs/digest" },
    "payload/base64": { "type": "string", "maxLength": 1398104, "contentEncoding": "base64" }
  },
  "allOf": [
    { "if": { "properties": { "frame/kind": { "enum": ["request", "chunk", "result", "error"] } }, "required": ["frame/kind"] }, "then": { "required": ["operation/id", "operation/kind"] } },
    { "if": { "properties": { "frame/kind": { "const": "chunk" } }, "required": ["frame/kind"] }, "then": { "required": ["chunk/index", "chunk/count", "payload/base64"], "properties": { "payload/length": { "maximum": 65536 } } } }
  ],
  "$defs": {
    "ref": { "type": "string", "minLength": 1, "maxLength": 256, "not": { "pattern": "\\u0000" } },
    "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
  }
}
