{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.glixo.dev/extension-manifest/v2.json",
  "title": "Extension Manifest v2",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "id", "version", "metadata"],
  "properties": {
    "$schema": { "type": "string" },
    "schemaVersion": { "type": "integer", "const": 2 },
    "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
    "version": { "type": "string", "pattern": "^\\d+\\.\\d+\\.\\d+" },
    "metadata": { "$ref": "#/$defs/ExtensionMetadata" },
    "compatibility": { "$ref": "#/$defs/ExtensionCompatibility" },
    "artifacts": {
      "type": "array",
      "items": { "$ref": "#/$defs/ExtensionArtifact" }
    },
    "components": {
      "type": "array",
      "items": { "$ref": "#/$defs/ExtensionComponent" }
    },
    "cells": {
      "type": "array",
      "items": { "type": "string", "enum": ["server", "desktop", "os", "mobile", "browser"] }
    },
    "permissions": { "$ref": "#/$defs/ExtensionPermissions" },
    "events": { "$ref": "#/$defs/ExtensionEvents" },
    "configurations": {
      "type": "array",
      "items": { "$ref": "#/$defs/ExtensionConfigurationRef" }
    },
    "contributions": { "$ref": "#/$defs/ExtensionContributions" }
  },
  "$defs": {
    "ExtensionMetadata": {
      "type": "object",
      "additionalProperties": false,
      "required": ["name"],
      "properties": {
        "name": { "type": "string", "minLength": 1 },
        "description": { "type": "string" },
        "license": { "type": "string" }
      }
    },
    "ExtensionCompatibility": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "host": { "type": "string", "minLength": 1 },
        "schema": { "type": "integer", "const": 2 },
        "witWorld": { "type": "string" },
        "uiBridge": { "type": "string" },
        "packageSignature": { "type": "string" },
        "trustTier": { "type": "string", "enum": ["marketplace", "local-trusted", "admin"] },
        "compositionKind": { "$ref": "#/$defs/PackageCompositionKind" },
        "productId": { "type": "string", "enum": ["glixo-code", "glixo-os", "glixo-mobile", "glixo-workflow-designer"] }
      }
    },
    "ExtensionArtifact": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "digest"],
      "properties": {
        "path": { "type": "string", "pattern": "^(?!\\/)(?!.*\\.\\.).+$" },
        "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "mediaType": {
          "type": "string",
          "enum": [
            "application/wasm",
            "text/html",
            "text/css",
            "text/javascript",
            "application/json",
            "image/png",
            "image/svg+xml",
            "image/webp",
            "application/json+a2ui",
            "application/json+theme-tokens"
          ]
        }
      }
    },
    "ExtensionComponent": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "cell", "runtime"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "cell": { "type": "string", "enum": ["server", "desktop", "os", "mobile", "browser"] },
        "runtime": { "type": "string", "enum": ["wasm-component", "sandboxed-web", "local-process"] },
        "artifact": { "type": "string" },
        "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "world": { "type": "string" },
        "entry": { "type": "string" }
      }
    },
    "ExtensionPermissions": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "requested": {
          "type": "array",
          "items": { "$ref": "#/$defs/RequestedPermission" }
        }
      }
    },
    "RequestedPermission": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "reason"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "scope": { "type": "object", "additionalProperties": true },
        "reason": { "type": "string", "minLength": 1 }
      }
    },
    "ExtensionEvents": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "publish": { "type": "array", "items": { "$ref": "#/$defs/EventPublishDeclaration" } },
        "subscribe": { "type": "array", "items": { "$ref": "#/$defs/EventSubscribeDeclaration" } }
      }
    },
    "EventPublishDeclaration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "schemaVersion", "scope", "reason"],
      "properties": {
        "type": { "type": "string", "minLength": 1 },
        "schema": { "type": "string" },
        "schemaVersion": { "type": "integer", "minimum": 1 },
        "scope": { "type": "string", "enum": ["account", "workspace", "project", "installation"] },
        "reason": { "type": "string", "minLength": 1 }
      }
    },
    "EventSubscribeDeclaration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["type", "schemaVersions", "scope", "reason"],
      "properties": {
        "type": { "type": "string", "minLength": 1 },
        "schemaVersions": { "type": "array", "items": { "type": "integer", "minimum": 1 } },
        "scope": { "type": "string", "enum": ["account", "workspace", "project", "installation"] },
        "delivery": { "type": "string", "enum": ["durable", "wake"] },
        "component": { "type": "string" },
        "handler": { "type": "string" },
        "publisherPackageId": { "type": "string", "minLength": 1 },
        "publisherKinds": {
          "type": "array",
          "items": { "type": "string", "enum": ["extension", "extension-service", "platform", "workflow", "application"] }
        },
        "reason": { "type": "string", "minLength": 1 }
      }
    },
    "ExtensionConfigurationRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "scope", "schema", "schemaDigest"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "scope": { "type": "string", "enum": ["installation", "account", "user", "workspace", "project", "session"] },
        "schema": { "type": "string" },
        "schemaDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "ui": { "type": "string" },
        "uiDigest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
      },
      "allOf": [{ "if": { "required": ["ui"] }, "then": { "required": ["uiDigest"] } }]
    },
    "ExtensionContributions": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "providerFamilies": { "type": "array", "items": { "$ref": "#/$defs/ProviderFamilyContribution" } },
        "llmProviders": { "type": "array", "items": { "$ref": "#/$defs/LlmProviderContributionRef" } },
        "gitProviders": { "type": "array", "items": { "$ref": "#/$defs/GitProviderContributionRef" } },
        "storageProviders": { "type": "array", "items": { "$ref": "#/$defs/ContributionRef" } },
        "skills": { "type": "array", "items": { "$ref": "#/$defs/ContributionRef" } },
        "themes": { "type": "array", "items": { "$ref": "#/$defs/SurfaceContribution" } },
        "a2ui": { "type": "array", "items": { "$ref": "#/$defs/SurfaceContribution" } },
        "sandboxedWebUi": { "type": "array", "items": { "$ref": "#/$defs/SurfaceContribution" } },
        "actions": { "type": "array", "items": { "$ref": "#/$defs/ActionContribution" } },
        "surfaces": { "type": "array", "items": { "$ref": "#/$defs/SurfaceContribution" } },
        "tools": { "type": "array", "items": { "$ref": "#/$defs/ToolContribution" } },
        "mcp": { "type": "array", "items": { "$ref": "#/$defs/McpContribution" } },
        "dataSources": { "type": "array", "items": { "$ref": "#/$defs/DataSourceContribution" } },
        "backgroundServices": { "type": "array", "items": { "$ref": "#/$defs/BackgroundServiceContribution" } },
        "messageMiddleware": { "type": "array", "items": { "$ref": "#/$defs/MessageMiddlewareContribution" } }
      }
    },
    "DataSourceContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "component", "querySchema", "resultSchema", "pagination", "freshnessMs", "provenance", "cache", "cancellable", "redaction", "maxResults"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "component": { "type": "string", "minLength": 1 },
        "configuration": { "type": "string" },
        "world": { "type": "string" },
        "cell": { "type": "string", "enum": ["server", "desktop", "os", "mobile", "browser"] },
        "targetApplications": {
          "type": "array",
          "items": { "type": "string", "pattern": "^app\\.[a-z0-9][a-z0-9.-]{1,127}$" }
        },
        "querySchema": { "type": "object" },
        "resultSchema": { "type": "object" },
        "pagination": { "type": "string", "enum": ["none", "page", "cursor", "stream"] },
        "freshnessMs": { "type": "integer", "minimum": 1 },
        "provenance": { "type": "boolean" },
        "cache": { "type": "string", "enum": ["none", "private", "shared"] },
        "cancellable": { "type": "boolean" },
        "redaction": { "type": "string", "enum": ["none", "secrets", "pii"] },
        "maxResults": { "type": "integer", "minimum": 1, "maximum": 1000 },
        "timeoutMs": { "type": "integer", "minimum": 1 },
        "export": { "type": "string", "minLength": 1 }
      }
    },
    "MessageMiddlewareContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "component", "hooks", "order", "failurePolicy"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "component": { "type": "string", "minLength": 1 },
        "world": { "type": "string", "const": "glixo:contribution/contribution@1.0.0" },
        "configuration": { "type": "string", "minLength": 1 },
        "targetApplications": { "type": "array", "uniqueItems": true, "items": { "type": "string", "pattern": "^app\\.[a-z0-9][a-z0-9.-]{1,127}$" } },
        "hooks": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "enum": ["before-provider", "completed", "committed", "transform-response"] } },
        "order": { "type": "integer", "minimum": -1000, "maximum": 1000 },
        "failurePolicy": { "type": "string", "enum": ["block", "continue"] },
        "timeoutMs": { "type": "integer", "minimum": 1, "maximum": 30000 },
        "maxBytes": { "type": "integer", "minimum": 1, "maximum": 131072 }
      }
    },
    "BackgroundServiceContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "component", "archetype", "activation", "quota", "retry", "idempotent", "health", "shutdown"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "component": { "type": "string", "minLength": 1 },
        "configuration": { "type": "string" },
        "world": { "type": "string" },
        "cell": { "type": "string", "enum": ["server", "desktop", "os", "mobile", "browser"] },
        "archetype": { "type": "string", "enum": ["event-handler", "scheduled", "webhook-ingest"] },
        "schedule": {
          "type": "object",
          "additionalProperties": false,
          "required": ["intervalMs"],
          "properties": {
            "intervalMs": { "type": "integer", "minimum": 1000, "maximum": 86400000 }
          }
        },
        "activation": { "type": "string", "enum": ["install", "grant", "manual"] },
        "quota": { "type": "integer", "minimum": 1, "maximum": 64 },
        "retry": { "type": "integer", "minimum": 0, "maximum": 8 },
        "idempotent": { "type": "boolean" },
        "health": { "type": "string", "enum": ["none", "export", "event"] },
        "shutdown": { "type": "string", "enum": ["graceful", "immediate"] },
        "timeoutMs": { "type": "integer", "minimum": 1, "maximum": 30000 },
        "export": { "type": "string", "minLength": 1 }
      },
      "allOf": [
        { "if": { "properties": { "archetype": { "const": "scheduled" } }, "required": ["archetype"] }, "then": { "required": ["schedule"] }, "else": { "not": { "required": ["schedule"] } } }
      ]
    },
    "ToolContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "description", "inputSchema", "outputSchema"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "component": { "type": "string" },
        "configuration": { "type": "string" },
        "world": { "type": "string" },
        "targetApplications": {
          "type": "array",
          "items": { "type": "string", "pattern": "^app\\.[a-z0-9][a-z0-9.-]{1,127}$" }
        },
        "description": { "type": "string", "minLength": 1 },
        "inputSchema": { "type": "object" },
        "outputSchema": { "type": "object" },
        "safety": { "type": "string", "enum": ["readonly", "mutating", "privileged"] },
        "timeoutMs": { "type": "integer", "minimum": 1 },
        "cancellable": { "type": "boolean" },
        "idempotent": { "type": "boolean" },
        "export": { "type": "string", "minLength": 1 },
        "confirmation": { "type": "string", "enum": ["install", "invoke"] }
      }
    },
    "McpContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "transport"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "component": { "type": "string" },
        "configuration": { "type": "string" },
        "transport": { "type": "string", "enum": ["remote-http", "wasm-component", "stdio"] },
        "endpoint": { "type": "string", "minLength": 1 },
        "command": { "type": "string", "minLength": 1 }
      }
    },
    "PackageCompositionKind": {
      "type": "string",
      "description": "Host product composition, not publisher reputation. local-trusted and admin trust tiers never grant in-process UI.",
      "enum": ["marketplace", "signed-host-product"]
    },
    "UiTier": {
      "type": "string",
      "description": "Canonical UI trust tiers. native-privileged is signed first-party product composition compiled into the host, never marketplace or publisher-trusted packages.",
      "enum": ["declarative", "a2ui", "sandboxed-web", "theme", "native-privileged"]
    },
    "UiOriginPolicy": {
      "type": "string",
      "enum": ["opaque-extension", "host-product"]
    },
    "UiAsset": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "digest", "mediaType"],
      "properties": {
        "path": { "type": "string", "pattern": "^(?!\\/)(?!.*\\.\\.)(?![a-z][a-z0-9+.-]*:)[a-z0-9][a-z0-9./_-]*$" },
        "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
        "mediaType": {
          "type": "string",
          "enum": [
            "text/html",
            "text/css",
            "text/javascript",
            "application/json",
            "image/png",
            "image/svg+xml",
            "image/webp",
            "application/json+a2ui",
            "application/json+theme-tokens"
          ]
        }
      }
    },
    "UiContributionRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "id"],
      "properties": {
        "kind": { "type": "string", "enum": ["configuration", "data", "action"] },
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" }
      }
    },
    "UiLimits": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "maxTreeDepth": { "type": "integer", "minimum": 1, "maximum": 32 },
        "maxNodes": { "type": "integer", "minimum": 1, "maximum": 4096 },
        "maxStringBytes": { "type": "integer", "minimum": 1, "maximum": 65536 },
        "maxAssetBytes": { "type": "integer", "minimum": 1, "maximum": 1048576 },
        "maxAssets": { "type": "integer", "minimum": 1, "maximum": 32 }
      }
    },
    "UiContributionCompatibility": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schema": { "type": "integer", "const": 2 },
        "uiBridge": { "type": "string", "minLength": 1 },
        "requiresRuntime": { "type": "boolean", "const": false }
      }
    },
    "DeclarativeSurfaceContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "uiTier", "placements"],
      "properties": {
        "id": { "type": "string" },
        "uiTier": { "type": "string", "const": "declarative" },
        "title": { "type": "string" },
        "placements": { "type": "array", "items": { "type": "string" } },
        "configuration": { "type": "string" },
        "data": { "type": "array", "items": { "$ref": "#/$defs/UiContributionRef" } },
        "actions": { "type": "array", "items": { "$ref": "#/$defs/UiContributionRef" } },
        "limits": { "$ref": "#/$defs/UiLimits" },
        "compatibility": { "$ref": "#/$defs/UiContributionCompatibility" },
        "targetApplications": { "type": "array", "items": { "type": "string" } },
        "context": { "type": "string" }
      }
    },
    "A2uiSurfaceContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "uiTier", "placements", "assets"],
      "properties": {
        "id": { "type": "string" },
        "uiTier": { "type": "string", "const": "a2ui" },
        "title": { "type": "string" },
        "placements": { "type": "array", "items": { "type": "string" } },
        "assets": { "type": "array", "items": { "$ref": "#/$defs/UiAsset" } },
        "configuration": { "type": "string" },
        "data": { "type": "array", "items": { "$ref": "#/$defs/UiContributionRef" } },
        "actions": { "type": "array", "items": { "$ref": "#/$defs/UiContributionRef" } },
        "limits": { "$ref": "#/$defs/UiLimits" },
        "compatibility": { "$ref": "#/$defs/UiContributionCompatibility" },
        "targetApplications": { "type": "array", "items": { "type": "string" } },
        "context": { "type": "string" }
      }
    },
    "SandboxedWebSurfaceContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "uiTier", "placements", "origin", "component"],
      "properties": {
        "id": { "type": "string" },
        "uiTier": { "type": "string", "const": "sandboxed-web" },
        "title": { "type": "string" },
        "placements": { "type": "array", "items": { "type": "string" } },
        "origin": { "type": "string", "const": "opaque-extension" },
        "component": { "type": "string" },
        "assets": { "type": "array", "items": { "$ref": "#/$defs/UiAsset" } },
        "configuration": { "type": "string" },
        "data": { "type": "array", "items": { "$ref": "#/$defs/UiContributionRef" } },
        "actions": { "type": "array", "items": { "$ref": "#/$defs/UiContributionRef" } },
        "limits": { "$ref": "#/$defs/UiLimits" },
        "compatibility": { "$ref": "#/$defs/UiContributionCompatibility" },
        "targetApplications": { "type": "array", "items": { "type": "string" } },
        "context": { "type": "string" }
      }
    },
    "ThemeSurfaceContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "uiTier", "placements", "assets"],
      "properties": {
        "id": { "type": "string" },
        "uiTier": { "type": "string", "const": "theme" },
        "title": { "type": "string" },
        "placements": { "type": "array", "items": { "type": "string" } },
        "assets": { "type": "array", "items": { "$ref": "#/$defs/UiAsset" } },
        "limits": { "$ref": "#/$defs/UiLimits" },
        "compatibility": { "$ref": "#/$defs/UiContributionCompatibility" },
        "targetApplications": { "type": "array", "items": { "type": "string" } },
        "context": { "type": "string" }
      }
    },
    "NativePrivilegedSurfaceContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "uiTier", "placements", "component", "origin"],
      "properties": {
        "id": { "type": "string" },
        "uiTier": { "type": "string", "const": "native-privileged" },
        "title": { "type": "string" },
        "placements": { "type": "array", "items": { "type": "string" } },
        "origin": { "type": "string", "const": "host-product" },
        "component": { "type": "string", "pattern": "^host\\.surface\\.[a-z0-9][a-z0-9.-]{1,127}$" },
        "configuration": { "type": "string" },
        "data": { "type": "array", "items": { "$ref": "#/$defs/UiContributionRef" } },
        "actions": { "type": "array", "items": { "$ref": "#/$defs/UiContributionRef" } },
        "compatibility": { "$ref": "#/$defs/UiContributionCompatibility" },
        "targetApplications": { "type": "array", "items": { "type": "string" } },
        "context": { "type": "string" }
      }
    },
    "ActionTarget": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind"],
      "properties": {
        "kind": { "type": "string", "enum": ["host-operation", "component-export"] },
        "operation": { "type": "string", "minLength": 1 },
        "export": { "type": "string", "minLength": 1 }
      }
    },
    "ActionEnablement": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "when": { "type": "string" },
        "disabledReason": { "type": "string" }
      }
    },
    "ProviderFamilyContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "branding"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{0,63}$" },
        "label": { "type": "string", "minLength": 1, "maxLength": 80 },
        "description": { "type": "string", "maxLength": 300 },
        "branding": { "$ref": "#/$defs/ProviderFamilyBrandingDeclaration" }
      }
    },
    "ProviderFamilyBrandingDeclaration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["monochromeSvg", "colorPng", "accentColor"],
      "properties": {
        "monochromeSvg": { "$ref": "#/$defs/ProviderMonochromeSvgAsset" },
        "colorPng": { "$ref": "#/$defs/ProviderColorPngAsset" },
        "accentColor": { "type": "string", "pattern": "^#[0-9A-Fa-f]{6}$" }
      }
    },
    "ProviderMonochromeSvgAsset": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "mediaType", "digest"],
      "properties": {
        "path": { "type": "string", "pattern": "^(?!/)(?!.*\\.\\.)(?!.*//)[A-Za-z0-9](?:[A-Za-z0-9._/-]*[A-Za-z0-9._-])?$" },
        "mediaType": { "type": "string", "const": "image/svg+xml" },
        "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
      }
    },
    "ProviderColorPngAsset": {
      "type": "object",
      "additionalProperties": false,
      "required": ["path", "mediaType", "digest"],
      "properties": {
        "path": { "type": "string", "pattern": "^(?!/)(?!.*\\.\\.)(?!.*//)[A-Za-z0-9](?:[A-Za-z0-9._/-]*[A-Za-z0-9._-])?$" },
        "mediaType": { "type": "string", "const": "image/png" },
        "digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }
      }
    },
    "ProviderFamilyId": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9.-]{1,127}/[a-z0-9][a-z0-9.-]{0,63}$"
    },
    "ProviderEnvironmentId": {
      "type": "string",
      "enum": ["glixo-ai-browser", "code-web-server", "tauri-windows", "tauri-macos", "tauri-linux", "android-companion", "android-paired", "ios"]
    },
    "ProviderCapabilityId": {
      "oneOf": [
        {
          "type": "string",
          "enum": ["provider.credentials.write", "provider.oauth.pkce", "provider.oauth.browser-relay", "host.browser.popup", "host.browser.system", "host.deep-link.callback", "provider.oauth.device-code", "host.secure-secret-store", "provider.cli-proxy", "llm.execution.browser", "llm.execution.server", "llm.execution.on-device", "llm.execution.paired-device", "llm.execution.extension", "network.https-egress"]
        },
        { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}/[a-z0-9][a-z0-9.-]{0,63}$" }
      ]
    },
    "ProviderAuthMethod": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "kind", "flow", "protocol", "transports", "supportedEnvironments", "requiredCapabilities", "credentialBindings"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{0,63}$" },
        "label": { "type": "string", "minLength": 1, "maxLength": 80 },
        "description": { "type": "string", "maxLength": 300 },
        "kind": { "type": "string", "enum": ["oauth", "credential"] },
        "flow": { "type": "string", "enum": ["manual-entry", "browser-authorization", "system-browser-authorization", "device-authorization", "connect-existing-service"] },
        "protocol": {
          "oneOf": [
            { "type": "string", "enum": ["none", "api-key", "oauth2-authorization-code", "oauth2-authorization-code-pkce", "oauth2-device-authorization", "cli-proxy", "provider.openrouter-pkce-key-exchange", "provider.openai-codex-oauth", "provider.gemini-oauth", "provider.managed-cliproxy-oauth"] },
            { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}/[a-z0-9][a-z0-9.-]{0,63}$" }
          ]
        },
        "transports": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": { "type": "string", "enum": ["host-managed", "credential-form", "browser-popup", "browser-relay-popup", "system-browser", "deep-link", "native-app-link", "device-code"] }
        },
        "supportedEnvironments": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/ProviderEnvironmentId" } },
        "requiredCapabilities": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/ProviderCapabilityId" } },
        "credentialBindings": { "type": "array", "uniqueItems": true, "items": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$" } }
      }
    },
    "GitProviderCredentialField": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "type"],
      "properties": {
        "id": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$" },
        "label": { "type": "string", "minLength": 1, "maxLength": 80 },
        "type": { "type": "string", "enum": ["url", "secret", "text", "oauth"] },
        "required": { "type": "boolean" },
        "secret": { "type": "boolean" },
        "helpText": { "type": "string", "maxLength": 300 },
        "defaultValue": { "type": "string", "maxLength": 256 }
      },
      "allOf": [
        { "if": { "properties": { "secret": { "const": true } }, "required": ["secret"] }, "then": { "not": { "required": ["defaultValue"] } } }
      ]
    },
    "GitProviderAuthMethod": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "kind", "flow", "protocol", "transports", "supportedEnvironments", "requiredCapabilities", "credentialBindings", "credentialFields"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{0,63}$" },
        "label": { "type": "string", "minLength": 1, "maxLength": 80 },
        "description": { "type": "string", "maxLength": 300 },
        "kind": { "type": "string", "enum": ["oauth", "credential"] },
        "flow": { "type": "string", "enum": ["manual-entry", "browser-authorization", "system-browser-authorization", "device-authorization", "connect-existing-service"] },
        "protocol": { "oneOf": [
          { "type": "string", "enum": ["none", "api-key", "oauth2-authorization-code", "oauth2-authorization-code-pkce", "oauth2-device-authorization", "cli-proxy", "provider.openrouter-pkce-key-exchange", "provider.openai-codex-oauth", "provider.gemini-oauth", "provider.managed-cliproxy-oauth"] },
          { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}/[a-z0-9][a-z0-9.-]{0,63}$" }
        ] },
        "transports": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "enum": ["host-managed", "credential-form", "browser-popup", "browser-relay-popup", "system-browser", "deep-link", "native-app-link", "device-code"] } },
        "supportedEnvironments": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/ProviderEnvironmentId" } },
        "requiredCapabilities": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/ProviderCapabilityId" } },
        "credentialBindings": { "type": "array", "uniqueItems": true, "items": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$" } },
        "credentialFields": { "type": "array", "items": { "$ref": "#/$defs/GitProviderCredentialField" } }
      }
    },
    "GitProviderInstanceDeclaration": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "defaultUrl": { "type": "string", "format": "uri", "pattern": "^https://" },
        "label": { "type": "string", "maxLength": 80 },
        "urlLabel": { "type": "string", "maxLength": 80 },
        "placeholder": { "type": "string", "maxLength": 160 },
        "allowCustomUrl": { "type": "boolean" }
      }
    },
    "GitProviderCapabilityId": {
      "type": "string",
      "oneOf": [
        { "type": "string", "enum": ["repositories.read", "repositories.clone", "api.read", "api.write", "pullRequests.read", "pullRequests.write", "ci.read", "mcp"] },
        { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}/[a-z0-9][a-z0-9.-]{0,63}$" }
      ]
    },
    "GitProviderMcpResourceBinding": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "resourceType", "headerName", "headerValuePrefix", "credentialBinding"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{0,63}$" },
        "resourceType": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{0,63}$" },
        "url": { "type": "string", "format": "uri", "maxLength": 2048, "pattern": "^(?!.*[?#\u005c\u005c\u005cs])https://[^/?#@]+(?:/[^?#]*)?$" },
        "relativePath": { "type": "string", "minLength": 1, "maxLength": 2048, "pattern": "^/(?!/)(?!\\.{1,2}(?:/|$))(?!.*\\/\\.{1,2}(?:/|$))(?!.*[?#\u005c\u005c\u005cs]).*$" },
        "headerName": { "type": "string", "pattern": "^[!#$%&'*+.^_`|~0-9A-Za-z-]{1,256}$" },
        "headerValuePrefix": { "type": "string", "maxLength": 64 },
        "credentialBinding": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$" },
        "required": { "type": "boolean" },
        "requiredScopes": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 128 } },
        "audience": { "type": "string", "minLength": 1, "maxLength": 256 }
      },
      "oneOf": [
        { "required": ["url"], "not": { "required": ["relativePath"] } },
        { "required": ["relativePath"], "not": { "required": ["url"] } }
      ]
    },
    "GitProviderMcpDeclaration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["resourceBindings"],
      "properties": {
        "resourceBindings": { "type": "array", "items": { "$ref": "#/$defs/GitProviderMcpResourceBinding" } }
      }
    },
    "GitProviderContributionRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "label", "authMethods", "supportedCapabilities", "contractId", "implementationId"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{0,63}$" },
        "label": { "type": "string", "minLength": 1, "maxLength": 80 },
        "description": { "type": "string", "maxLength": 300 },
        "authMethods": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/GitProviderAuthMethod" } },
        "supportedCapabilities": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/GitProviderCapabilityId" } },
        "contractId": { "type": "string", "const": "glixo.adapter.git.v1" },
        "implementationId": { "type": "string", "minLength": 1, "maxLength": 192, "pattern": "^[A-Za-z0-9][A-Za-z0-9._/-]*$" },
        "component": { "type": "string", "minLength": 1 },
        "configuration": { "type": "string", "minLength": 1 },
        "world": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]*:[a-z0-9][a-z0-9.-]*/[a-z0-9][a-z0-9.-]*@\\d+\\.\\d+\\.\\d+$" },
        "targetApplications": {
          "type": "array",
          "items": { "type": "string", "pattern": "^app\\.[a-z0-9][a-z0-9.-]{1,127}$" }
        },
        "placements": {
          "type": "array",
          "items": { "type": "string", "pattern": "^(suite|code|os|settings|command-palette|context-menu)(\\.[a-z0-9][a-z0-9.-]*)*$" }
        },
        "context": { "type": "string", "enum": ["machine", "project", "session"] },
        "instance": { "$ref": "#/$defs/GitProviderInstanceDeclaration" },
        "mcp": { "$ref": "#/$defs/GitProviderMcpDeclaration" }
      }
    },
    "ProviderExecutionDeclaration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["target", "supportedEnvironments", "requiredCapabilities"],
      "properties": {
        "target": { "type": "string", "enum": ["browser-sandbox", "server", "on-device", "paired-device", "extension-host"] },
        "supportedEnvironments": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "$ref": "#/$defs/ProviderEnvironmentId" } },
        "requiredCapabilities": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/ProviderCapabilityId" } }
      }
    },
    "LlmProviderContributionRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "familyId", "authMethods", "execution"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "familyId": { "$ref": "#/$defs/ProviderFamilyId" },
        "authMethods": { "type": "array", "minItems": 1, "items": { "$ref": "#/$defs/ProviderAuthMethod" } },
        "execution": { "$ref": "#/$defs/ProviderExecutionDeclaration" },
        "component": { "type": "string" },
        "configuration": { "type": "string" },
        "world": { "type": "string" },
        "targetApplications": {
          "type": "array",
          "items": { "type": "string", "pattern": "^app\\.[a-z0-9][a-z0-9.-]{1,127}$" }
        },
        "placements": {
          "type": "array",
          "items": { "type": "string", "pattern": "^(suite|code|os|settings|command-palette|context-menu)(\\.[a-z0-9][a-z0-9.-]*)*$" }
        },
        "context": { "type": "string", "enum": ["machine", "project", "session"] },
        "accountStatus": { "$ref": "#/$defs/LlmAccountStatusDeclaration" }
      }
    },
    "LlmAccountStatusDeclaration": {
      "type": "object",
      "additionalProperties": false,
      "required": ["interfaceVersion"],
      "properties": {
        "interfaceVersion": { "type": "string", "minLength": 1, "maxLength": 64 },
        "requiredScopes": { "type": "array", "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 128 } },
        "requiredCapabilities": { "type": "array", "uniqueItems": true, "items": { "$ref": "#/$defs/ProviderCapabilityId" } },
        "credentialBindings": { "type": "array", "uniqueItems": true, "items": { "type": "string", "pattern": "^[A-Za-z][A-Za-z0-9_-]{0,63}$" } }
      }
    },
    "ContributionRef": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "component": { "type": "string" },
        "configuration": { "type": "string" },
        "world": { "type": "string" },
        "targetApplications": {
          "type": "array",
          "items": { "type": "string", "pattern": "^app\\.[a-z0-9][a-z0-9.-]{1,127}$" }
        },
        "placements": {
          "type": "array",
          "items": { "type": "string", "pattern": "^(suite|code|os|settings|command-palette|context-menu)(\\.[a-z0-9][a-z0-9.-]*)*$" }
        },
        "context": { "type": "string", "enum": ["machine", "project", "session"] }
      }
    },
    "ActionContribution": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "title": { "type": "string", "minLength": 1, "maxLength": 80 },
        "component": { "type": "string" },
        "configuration": { "type": "string" },
        "world": { "type": "string" },
        "targetApplications": {
          "type": "array",
          "items": { "type": "string", "pattern": "^app\\.[a-z0-9][a-z0-9.-]{1,127}$" }
        },
        "placements": {
          "type": "array",
          "items": { "type": "string", "pattern": "^(suite|code|os|settings|command-palette|context-menu)(\\.[a-z0-9][a-z0-9.-]*)*$" }
        },
        "context": { "type": "string", "enum": ["machine", "project", "session"] },
        "parameters": { "type": "object" },
        "result": { "type": "object" },
        "enablement": { "$ref": "#/$defs/ActionEnablement" },
        "target": { "$ref": "#/$defs/ActionTarget" },
        "timeoutMs": { "type": "integer", "minimum": 1 },
        "cancellable": { "type": "boolean" }
      }
    },
    "SurfaceContribution": {
      "type": "object",
      "description": "Closed UI contribution union discriminated by uiTier. Variant shapes are DeclarativeSurfaceContribution, A2uiSurfaceContribution, SandboxedWebSurfaceContribution, ThemeSurfaceContribution, and NativePrivilegedSurfaceContribution. Invalid tier/placement/origin/reference combinations fail before assets load. native-privileged requires signed-host-product composition, not trustTier.",
      "additionalProperties": false,
      "required": ["id", "uiTier"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "component": { "type": "string" },
        "configuration": { "type": "string", "pattern": "^[a-z0-9][a-z0-9.-]{1,127}$" },
        "world": { "type": "string" },
        "targetApplications": {
          "type": "array",
          "items": { "type": "string", "pattern": "^app\\.[a-z0-9][a-z0-9.-]{1,127}$" }
        },
        "placements": {
          "type": "array",
          "minItems": 1,
          "items": { "type": "string", "pattern": "^(suite|code|os|settings|command-palette|context-menu)(\\.[a-z0-9][a-z0-9.-]*)*$" }
        },
        "context": { "type": "string", "enum": ["machine", "project", "session"] },
        "uiTier": { "$ref": "#/$defs/UiTier" },
        "title": { "type": "string", "minLength": 1 },
        "assets": {
          "type": "array",
          "maxItems": 32,
          "items": { "$ref": "#/$defs/UiAsset" }
        },
        "data": {
          "type": "array",
          "items": { "$ref": "#/$defs/UiContributionRef" }
        },
        "actions": {
          "type": "array",
          "items": { "$ref": "#/$defs/UiContributionRef" }
        },
        "origin": { "$ref": "#/$defs/UiOriginPolicy" },
        "limits": { "$ref": "#/$defs/UiLimits" },
        "compatibility": { "$ref": "#/$defs/UiContributionCompatibility" }
      },
      "allOf": [
        {
          "if": { "properties": { "uiTier": { "const": "native-privileged" } }, "required": ["uiTier"] },
          "then": { "required": ["component", "origin", "placements"] }
        },
        {
          "if": { "properties": { "uiTier": { "const": "sandboxed-web" } }, "required": ["uiTier"] },
          "then": { "required": ["component", "origin", "placements"] }
        },
        {
          "if": { "properties": { "uiTier": { "const": "a2ui" } }, "required": ["uiTier"] },
          "then": { "required": ["assets", "placements"] }
        },
        {
          "if": { "properties": { "uiTier": { "const": "theme" } }, "required": ["uiTier"] },
          "then": { "required": ["placements", "assets"] }
        },
        {
          "if": { "properties": { "uiTier": { "const": "declarative" } }, "required": ["uiTier"] },
          "then": { "required": ["placements"] }
        }
      ]
    }
  }
}
