{
  "$schema": "https://json-schema.org/draft-07/schema#",
  "title": "ManAurum App Manifest",
  "description": "Schema for ManAurum OS third-party app manifests",
  "type": "object",
  "required": ["manifest_version", "app_id", "name", "version", "runtime", "window"],
  "properties": {
    "manifest_version": {
      "type": "integer",
      "const": 1,
      "description": "Manifest schema version. Always 1."
    },
    "app_id": {
      "type": "string",
      "pattern": "^[a-z0-9][a-z0-9\\-]{1,48}[a-z0-9]$",
      "description": "Unique app identifier. Lowercase alphanumeric + hyphens, 3-50 chars."
    },
    "name": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100,
      "description": "Display name of the app."
    },
    "version": {
      "type": "string",
      "pattern": "^\\d+\\.\\d+\\.\\d+$",
      "description": "Semantic version: X.Y.Z"
    },
    "developer_id": {
      "type": "string",
      "description": "UUID of the developer. Set by the platform."
    },
    "description": {
      "type": "object",
      "required": ["short"],
      "properties": {
        "short": { "type": "string", "minLength": 1, "maxLength": 160, "description": "Short description for App Store listing." },
        "long": { "type": "string", "maxLength": 5000, "description": "Full description with details." }
      }
    },
    "icon": {
      "type": "string",
      "description": "HTTPS URL to app icon. PNG/SVG, 256x256 recommended."
    },
    "category": {
      "type": "string",
      "enum": ["productivity", "utility", "lifestyle", "entertainment", "dev_tools", "other"],
      "description": "App Store category."
    },
    "tags": {
      "type": "array",
      "items": { "type": "string" },
      "maxItems": 10,
      "description": "Search tags for discoverability."
    },
    "runtime": {
      "type": "object",
      "required": ["type", "entrypoint"],
      "properties": {
        "type": { "type": "string", "enum": ["iframe"], "description": "Runtime type. Always 'iframe' for third-party apps." },
        "entrypoint": { "type": "string", "format": "uri", "pattern": "^https://", "description": "HTTPS URL of your app." },
        "sandbox": {
          "type": "array",
          "items": { "type": "string", "enum": ["allow-scripts", "allow-forms", "allow-same-origin"] },
          "default": ["allow-scripts", "allow-forms", "allow-same-origin"],
          "description": "Iframe sandbox attributes."
        }
      }
    },
    "window": {
      "type": "object",
      "required": ["default_size"],
      "properties": {
        "default_size": {
          "type": "object",
          "required": ["width", "height"],
          "properties": {
            "width": { "type": "integer", "minimum": 300, "maximum": 2000 },
            "height": { "type": "integer", "minimum": 200, "maximum": 1500 }
          }
        },
        "min_size": {
          "type": "object",
          "properties": {
            "width": { "type": "integer", "minimum": 200 },
            "height": { "type": "integer", "minimum": 150 }
          }
        },
        "title": { "type": "string", "description": "Default window title." }
      }
    },
    "permissions": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": ["user.profile.read", "theme.read", "window.manage", "toast.send", "notifications.send", "notifications.schedule", "tasks.suggest", "storage.read", "storage.write", "files.read", "files.write"]
      },
      "description": "Permissions your app requests. Users see these before installing."
    },
    "platforms": {
      "type": "object",
      "description": "Platform support declarations. Both desktop and mobile should be explicitly declared.",
      "properties": {
        "desktop": {
          "type": "object",
          "properties": {
            "supported": { "type": "boolean", "default": true, "description": "Whether the app supports desktop." }
          }
        },
        "mobile": {
          "type": "object",
          "properties": {
            "supported": { "type": "boolean", "default": false, "description": "Whether the app supports mobile." },
            "optimized": { "type": "boolean", "default": false, "description": "Whether the app has mobile-optimized UI." },
            "entrypoint": { "type": "string", "format": "uri", "description": "Optional separate HTTPS entrypoint for mobile." },
            "supportLevel": {
              "type": "string",
              "enum": ["full", "adaptive", "fallback", "none"],
              "default": "none",
              "description": "full = dedicated mobile UI, adaptive = responsive, fallback = desktop UI with warning, none = blocked."
            },
            "navigationPattern": {
              "type": "string",
              "enum": ["stack", "tabs", "list-detail", "single-view", "composer-first"],
              "description": "Primary navigation pattern the app uses on mobile."
            }
          }
        }
      }
    },
    "compatibility": {
      "type": "object",
      "properties": {
        "min_shell_version": { "type": "string", "default": "1.0.0" }
      }
    },
    "agent": {
      "type": "object",
      "description": "AI Agent integration. Allows the OS Assistant to route actions to your app.",
      "properties": {
        "enabled": {
          "type": "boolean",
          "default": false,
          "description": "Whether this app supports AI Assistant routing."
        },
        "capabilities": {
          "type": "array",
          "description": "Actions the OS Assistant can route to this app.",
          "items": {
            "type": "object",
            "required": ["name", "description", "input_schema"],
            "properties": {
              "name": {
                "type": "string",
                "description": "Unique capability name (e.g. 'create_todo', 'log_expense')."
              },
              "description": {
                "type": "string",
                "description": "What this capability does. Used by AI to decide routing."
              },
              "input_schema": {
                "type": "object",
                "description": "JSON Schema for the action input fields.",
                "additionalProperties": {
                  "type": "object",
                  "properties": {
                    "type": { "type": "string", "enum": ["string", "number", "boolean", "date", "time", "datetime", "json"] },
                    "required": { "type": "boolean", "default": false },
                    "description": { "type": "string" },
                    "enum": { "type": "array", "items": { "type": "string" } }
                  }
                }
              },
              "routing_hints": {
                "type": "array",
                "items": { "type": "string" },
                "description": "Keywords that suggest this capability (e.g. ['todo', 'task', 'remind'])."
              },
              "trust_default": {
                "type": "string",
                "enum": ["suggest", "auto_save", "auto_execute"],
                "default": "suggest",
                "description": "Default trust level for this action."
              },
              "example": {
                "type": "object",
                "description": "Example input payload for this capability."
              }
            }
          }
        },
        "emitted_events": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Domain events this app emits (e.g. 'todo.created', 'expense.logged')."
        },
        "subscribed_events": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Events this app wants to receive from other apps."
        }
      }
    }
  }
}
