{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/VincentChuWaiChow/vanguard-frontier-agentic/skills/cross-functional/atlassian-case-capsule/assets/atlassian-case-capsule.schema.json",
  "title": "Atlassian Case Capsule",
  "description": "The only handoff record between Atlassian board agents (skills/cross-functional/atlassian-case-capsule). Shape only: policy rules that JSON Schema cannot express (human-only approval, prohibited tools, tenant binding, expiry against as_of, delegation cycles, completion evidence, credential-shaped strings) are enforced by scripts/validate_capsule.py in this skill. A capsule never carries credentials and never confers authority by itself.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "task_id",
    "as_of",
    "origin_agent",
    "target_agent",
    "hop_type",
    "delegation_chain",
    "requested_decision",
    "business_context",
    "scope",
    "tenant_context",
    "user_identity_context",
    "evidence_references",
    "assumptions",
    "confidence",
    "execution_tier",
    "permitted_operations",
    "approval_state",
    "execution_budget",
    "deadline_or_expiry",
    "expected_output",
    "verification_requirements",
    "verification_evidence",
    "parent_task_id",
    "budget_consumed",
    "handoff_status",
    "decision_owner",
    "do_not_do"
  ],
  "$defs": {
    "agentId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9-]*-agent$"
    },
    "timestamp": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$"
    },
    "principal": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "principal_type",
        "account_ref"
      ],
      "properties": {
        "principal_type": {
          "enum": [
            "human",
            "agent",
            "service-account"
          ]
        },
        "account_ref": {
          "type": "string",
          "pattern": "^[A-Za-z0-9][A-Za-z0-9:_.-]{0,127}$",
          "description": "Opaque reference; never an email address, token, or password. Compared case-insensitively."
        }
      }
    }
  },
  "properties": {
    "schema_version": {
      "const": "1.0"
    },
    "task_id": {
      "type": "string",
      "minLength": 1
    },
    "as_of": {
      "$ref": "#/$defs/timestamp",
      "description": "The capsule's own clock. Gates compare expiry against this value and never read the wall clock."
    },
    "origin_agent": {
      "$ref": "#/$defs/agentId"
    },
    "target_agent": {
      "$ref": "#/$defs/agentId"
    },
    "hop_type": {
      "enum": [
        "delegate",
        "return"
      ],
      "description": "delegate: hand work onward to an agent not yet in the chain. return: send a result back exactly one hop, to delegation_chain[-2]."
    },
    "delegation_chain": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/agentId"
      }
    },
    "requested_decision": {
      "type": "string",
      "minLength": 1
    },
    "business_context": {
      "type": "string",
      "minLength": 1
    },
    "scope": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "products",
        "containers"
      ],
      "properties": {
        "products": {
          "type": "array",
          "minItems": 1,
          "items": {
            "enum": [
              "jira",
              "jira-service-management",
              "confluence",
              "jira-product-discovery",
              "bitbucket",
              "teamwork-graph"
            ]
          }
        },
        "containers": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "tenant_context": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "cloud_id",
        "site_url"
      ],
      "properties": {
        "cloud_id": {
          "type": "string",
          "minLength": 1
        },
        "site_url": {
          "type": "string",
          "pattern": "^https://[a-z0-9-]+\\.atlassian\\.net/?$"
        }
      }
    },
    "user_identity_context": {
      "$ref": "#/$defs/principal"
    },
    "evidence_references": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "id",
          "kind",
          "locator",
          "retrieved_at",
          "version",
          "trust",
          "contains_instructions"
        ],
        "properties": {
          "id": {
            "type": "string",
            "minLength": 1
          },
          "kind": {
            "enum": [
              "jira-issue",
              "jira-comment",
              "confluence-page",
              "confluence-comment",
              "jsm-request",
              "jsm-alert",
              "bitbucket-change",
              "external-record",
              "user-statement",
              "tool-output"
            ]
          },
          "locator": {
            "type": "string",
            "minLength": 1
          },
          "retrieved_at": {
            "$ref": "#/$defs/timestamp"
          },
          "version": {
            "type": "string"
          },
          "trust": {
            "enum": [
              "system-metadata",
              "untrusted-content",
              "user-supplied"
            ]
          },
          "contains_instructions": {
            "type": "boolean"
          }
        }
      }
    },
    "assumptions": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "confidence": {
      "enum": [
        "high",
        "moderate",
        "low",
        "unknown"
      ]
    },
    "execution_tier": {
      "enum": [
        "T0-research",
        "T1-read",
        "T2-draft",
        "T3-authorized-write",
        "T4-high-risk"
      ]
    },
    "permitted_operations": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "op_id",
          "tool",
          "target",
          "cloud_id"
        ],
        "properties": {
          "op_id": {
            "type": "string",
            "pattern": "^op-[a-z0-9-]{1,32}$",
            "description": "Unique within the capsule; verification_evidence entries reference it."
          },
          "tool": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9]*$"
          },
          "target": {
            "type": "string",
            "minLength": 1
          },
          "cloud_id": {
            "type": "string",
            "minLength": 1
          }
        }
      },
      "maxItems": 50
    },
    "approval_state": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "approvers",
        "approval_record",
        "approved_at",
        "expires_at"
      ],
      "properties": {
        "status": {
          "enum": [
            "not-required",
            "pending",
            "approved",
            "rejected",
            "expired"
          ]
        },
        "approvers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/principal"
          }
        },
        "approval_record": {
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": false,
          "required": [
            "kind",
            "locator"
          ],
          "properties": {
            "kind": {
              "enum": [
                "out-of-band-human-record",
                "jira-comment",
                "confluence-page",
                "agent-message",
                "chat-transcript"
              ]
            },
            "locator": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "approved_at": {
          "oneOf": [
            {
              "$ref": "#/$defs/timestamp"
            },
            {
              "type": "null"
            }
          ]
        },
        "expires_at": {
          "oneOf": [
            {
              "$ref": "#/$defs/timestamp"
            },
            {
              "type": "null"
            }
          ]
        }
      }
    },
    "execution_budget": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "max_delegation_depth",
        "max_tool_calls",
        "max_retries",
        "max_review_rounds"
      ],
      "properties": {
        "max_delegation_depth": {
          "type": "integer",
          "minimum": 1,
          "maximum": 3
        },
        "max_tool_calls": {
          "type": "integer",
          "minimum": 0,
          "maximum": 200
        },
        "max_retries": {
          "type": "integer",
          "minimum": 0,
          "maximum": 4
        },
        "max_review_rounds": {
          "type": "integer",
          "minimum": 0,
          "maximum": 2
        }
      }
    },
    "deadline_or_expiry": {
      "$ref": "#/$defs/timestamp"
    },
    "expected_output": {
      "type": "string",
      "minLength": 1
    },
    "verification_requirements": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "verification_evidence": {
      "type": "array",
      "description": "Read-back observations. Each names the permitted write target it verifies and the item actually read: the same item for an edit, or the item a create returned. Free text is not evidence.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "verifies",
          "target",
          "tool",
          "observed_state",
          "read_at"
        ],
        "properties": {
          "verifies": {
            "type": "string",
            "minLength": 1,
            "description": "The op_id of the write this read-back verifies."
          },
          "target": {
            "type": "string",
            "minLength": 1
          },
          "tool": {
            "type": "string",
            "pattern": "^[A-Za-z][A-Za-z0-9]*$"
          },
          "observed_state": {
            "type": "string",
            "minLength": 8
          },
          "read_at": {
            "$ref": "#/$defs/timestamp"
          }
        }
      }
    },
    "handoff_status": {
      "enum": [
        "proposed",
        "accepted",
        "rejected",
        "completed",
        "failed",
        "escalated",
        "expired"
      ]
    },
    "decision_owner": {
      "type": "string",
      "minLength": 1,
      "description": "A named human role accountable for the next decision; never an agent id."
    },
    "do_not_do": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "parent_task_id": {
      "type": [
        "string",
        "null"
      ],
      "minLength": 1,
      "description": "task_id of the capsule this one answers or continues; null for a new matter. Cross-capsule cycle detection needs a store this repository does not provide."
    },
    "budget_consumed": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "tool_calls",
        "retries",
        "review_rounds"
      ],
      "properties": {
        "tool_calls": {
          "type": "integer",
          "minimum": 0
        },
        "retries": {
          "type": "integer",
          "minimum": 0
        },
        "review_rounds": {
          "type": "integer",
          "minimum": 0
        }
      },
      "description": "What this hop has used so far. Delegation depth is the delegation_chain length, checked separately."
    }
  }
}
