{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://docs.shimpz.com/specs/assistant/v1/manifest.schema.json",
  "title": "Shimpz Assistant Manifest v1",
  "description": "Closed representation of shimpz.assistant.toml. The stdlib parser remains authoritative for semantic and secret-like-value checks.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schema_version",
    "id",
    "title",
    "version",
    "summary",
    "skill",
    "artifact",
    "operations",
    "permissions"
  ],
  "properties": {
    "schema_version": {
      "const": 1
    },
    "id": {
      "$ref": "#/$defs/id"
    },
    "title": {
      "$ref": "#/$defs/title"
    },
    "version": {
      "type": "string",
      "maxLength": 40,
      "pattern": "^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)$"
    },
    "summary": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240,
      "pattern": "^(?!\\s)(?!.*\\s$)[^\\r\\n]+$"
    },
    "skill": {
      "$ref": "#/$defs/skillPath"
    },
    "artifact": {
      "$ref": "#/$defs/artifact"
    },
    "operations": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/operation"
      }
    },
    "permissions": {
      "$ref": "#/$defs/permissions"
    },
    "routines": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/routine"
      }
    }
  },
  "$defs": {
    "id": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80,
      "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$"
    },
    "title": {
      "type": "string",
      "minLength": 1,
      "maxLength": 80,
      "pattern": "^(?!\\s)(?!.*\\s$)[^\\r\\n]+$"
    },
    "interface": {
      "type": "string",
      "maxLength": 100,
      "pattern": "^shimpz\\.[a-z][a-z0-9]*(?:-[a-z0-9]+)*/v[1-9][0-9]*$"
    },
    "remoteOperation": {
      "type": "string",
      "pattern": "^[a-z][a-z0-9]*(?:-[a-z0-9]+)*(?:\\.[a-z][a-z0-9]*(?:-[a-z0-9]+)*)*$"
    },
    "schemaPath": {
      "type": "string",
      "maxLength": 200,
      "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*//)[A-Za-z0-9][A-Za-z0-9._/-]*\\.json$"
    },
    "skillPath": {
      "type": "string",
      "maxLength": 200,
      "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.(?:/|$))(?!.*//)[A-Za-z0-9][A-Za-z0-9._/-]*\\.md$"
    },
    "artifact": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "port",
        "health_path",
        "architectures"
      ],
      "properties": {
        "mode": {
          "enum": [
            "development",
            "release"
          ]
        },
        "source": {
          "const": "."
        },
        "image": {
          "type": "string",
          "maxLength": 300,
          "pattern": "^[a-z0-9](?:[a-z0-9.-]*[a-z0-9])?(?::[1-9][0-9]{0,4})?/[a-z0-9]+(?:[._/-][a-z0-9]+)*@sha256:[0-9a-f]{64}$"
        },
        "port": {
          "type": "integer",
          "minimum": 1,
          "maximum": 65535
        },
        "health_path": {
          "type": "string",
          "pattern": "^/(?!.*//)[a-z0-9][a-z0-9/_-]*$",
          "maxLength": 120
        },
        "architectures": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "enum": [
              "linux/amd64",
              "linux/arm64"
            ]
          }
        }
      },
      "oneOf": [
        {
          "properties": {
            "mode": {
              "const": "development"
            },
            "source": {
              "const": "."
            }
          },
          "required": [
            "source"
          ],
          "not": {
            "required": [
              "image"
            ]
          }
        },
        {
          "properties": {
            "mode": {
              "const": "release"
            }
          },
          "required": [
            "image"
          ],
          "not": {
            "required": [
              "source"
            ]
          }
        }
      ]
    },
    "operation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "summary",
        "input_schema",
        "output_schema",
        "approval"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "summary": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "^(?!\\s)(?!.*\\s$)[^\\r\\n]+$"
        },
        "input_schema": {
          "$ref": "#/$defs/schemaPath"
        },
        "output_schema": {
          "$ref": "#/$defs/schemaPath"
        },
        "approval": {
          "enum": [
            "none",
            "once",
            "each-run"
          ]
        }
      }
    },
    "permissions": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "egress"
      ],
      "properties": {
        "egress": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "string",
            "maxLength": 253,
            "pattern": "^(?![0-9]+(?:\\.[0-9]+){3}$)(?!.*\\.(?:example|home\\.arpa|internal|invalid|lan|local|localhost|onion|test)$)[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+$"
          }
        },
        "services": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/servicePermission"
          }
        },
        "assistants": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/assistantPermission"
          }
        }
      }
    },
    "servicePermission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "interface",
        "operations",
        "credential_refs"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "interface": {
          "$ref": "#/$defs/interface"
        },
        "operations": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/remoteOperation"
          }
        },
        "credential_refs": {
          "description": "Logical Capsule binding names only; never provider credential identifiers or values.",
          "type": "array",
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/id"
          }
        }
      }
    },
    "assistantPermission": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "interface",
        "operations"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "interface": {
          "$ref": "#/$defs/interface"
        },
        "operations": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/remoteOperation"
          }
        }
      }
    },
    "routine": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "operation",
        "interval_seconds",
        "timeout_seconds",
        "jitter_seconds",
        "enabled_by_default",
        "single_flight",
        "idempotency_key"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/id"
        },
        "operation": {
          "$ref": "#/$defs/id"
        },
        "interval_seconds": {
          "type": "integer",
          "minimum": 60,
          "maximum": 31536000
        },
        "timeout_seconds": {
          "type": "integer",
          "minimum": 1
        },
        "jitter_seconds": {
          "type": "integer",
          "minimum": 0
        },
        "enabled_by_default": {
          "const": false
        },
        "single_flight": {
          "const": true
        },
        "idempotency_key": {
          "type": "string",
          "minLength": 1,
          "maxLength": 160,
          "pattern": "^(?=.*\\{scheduled_at\\})(?:[A-Za-z0-9_.:-]|\\{(?:assistant_id|routine_id|scheduled_at)\\})+$"
        }
      }
    }
  }
}
