{
  "$id": "https://raw.githubusercontent.com/Mearman/agent-permissions/main/agent-permissions.schema.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string",
      "description": "JSON Schema URI for editor validation and autocomplete."
    },
    "defaultMode": {
      "type": "string",
      "enum": [
        "standard",
        "autonomous",
        "restricted",
        "readonly",
        "plan",
        "dontAsk",
        "acceptEdits",
        "bypassPermissions",
        "default",
        "auto"
      ],
      "description": "Default permission mode. Agent Permission Policy modes: standard, autonomous, restricted, readonly. Claude Code compatible modes: plan, dontAsk, acceptEdits, bypassPermissions, default.",
      "default": "standard"
    },
    "ceiling": {
      "type": "boolean",
      "description": "Marks this layer as a ceiling: the allow rules of deeper layers only take effect where this layer also allows. Deeper layers can still add deny and ask rules, and cannot loosen the default mode."
    },
    "activeProfile": {
      "type": "string",
      "description": "Name of the active profile from `profiles`. If unset, use the top-level permission tiers directly."
    },
    "permissions": {
      "type": "object",
      "properties": {
        "allow": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Tools auto-approved without prompting. Evaluated after deny rules.",
          "examples": [
            "Bash(git status)",
            "Bash(npm run test:*)",
            "Read",
            "Grep"
          ]
        },
        "deny": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Tools always denied — short-circuits before allow and ask. A deny cannot be overridden by an allow in any other source.",
          "examples": [
            "Bash(sudo:*)",
            "Bash(rm -rf /)",
            "Read(./.env)"
          ]
        },
        "ask": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Tools that always prompt, even in autonomous mode. Evaluated after deny but before allow.",
          "examples": [
            "Bash(git push:*)",
            "Bash(npm publish:*)"
          ]
        },
        "additionalDirectories": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Directories beyond project root that agents may access.",
          "examples": [
            "../shared-libs/",
            "/tmp/build-cache"
          ]
        },
        "defaultMode": {
          "type": "string",
          "enum": [
            "standard",
            "autonomous",
            "restricted",
            "readonly",
            "plan",
            "dontAsk",
            "acceptEdits",
            "bypassPermissions",
            "default",
            "auto"
          ],
          "description": "Default permission mode. Accepted here for Claude Code compatibility, or at the top level for the canonical placement.",
          "default": "standard"
        }
      },
      "additionalProperties": false,
      "description": "Tool permission rules — evaluated in deny → ask → allow order."
    },
    "rules": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "tool": {
            "type": "string",
            "description": "Canonical tool name.",
            "examples": [
              "Bash",
              "Read",
              "Write",
              "Edit",
              "Grep",
              "WebFetch",
              "Agent",
              "mcp__github__create_issue"
            ]
          },
          "pattern": {
            "description": "Pattern to match against tool input. When absent, matches any input.",
            "examples": [
              "npm run *",
              "./config/**",
              "git push --force:*"
            ],
            "type": "string"
          },
          "tier": {
            "type": "string",
            "enum": [
              "allow",
              "deny",
              "ask"
            ],
            "description": "Permission tier to apply when this rule matches."
          },
          "approvers": {
            "description": "On an ask rule: the roles and actors who may approve the request, and how long it may wait. An unresolved request expires as a deny.",
            "type": "object",
            "properties": {
              "roles": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Roles whose holders may approve the request."
              },
              "actors": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Actors who may approve the request. The requester is never one of them."
              },
              "timeoutSeconds": {
                "type": "integer",
                "exclusiveMinimum": 0,
                "maximum": 9007199254740991,
                "description": "How long the request may stay unresolved. An unresolved request expires as a deny."
              }
            },
            "additionalProperties": false
          },
          "hidden": {
            "description": "On a deny rule: also leave the tool out of the agent's tool list. The call is refused as a plain deny is. Only a rule with no pattern hides the whole tool.",
            "type": "boolean",
            "const": true
          },
          "when": {
            "description": "Optional conditions. All must match for the rule to apply (AND logic).",
            "type": "object",
            "properties": {
              "cwd": {
                "type": "string",
                "description": "Working directory pattern (glob)."
              },
              "branch": {
                "type": "string",
                "description": "Git branch name pattern (glob)."
              },
              "env": {
                "type": "object",
                "propertyNames": {
                  "type": "string"
                },
                "additionalProperties": {
                  "type": "string"
                },
                "description": "Environment variables that must each equal the given value (AND logic)."
              },
              "actor": {
                "type": "string",
                "description": "Actor pattern (glob): who is making the call, as the host reports it. Unknown when the host reports none."
              },
              "role": {
                "type": "string",
                "description": "Role pattern (glob): holds when the actor has a matching role, as the host reports the roles. Unknown when the host reports none."
              },
              "remote": {
                "type": "string",
                "description": "Git remote pattern (glob), matched against the origin as host/path in lower case, so git@github.com:Org/Repo.git and https://github.com/org/repo both match github.com/org/*."
              },
              "predicate": {
                "oneOf": [
                  {
                    "$ref": "#/definitions/__schema0"
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "and"
                      },
                      "left": {
                        "$ref": "#/definitions/__schema1"
                      },
                      "right": {
                        "$ref": "#/definitions/__schema1"
                      }
                    },
                    "required": [
                      "kind",
                      "left",
                      "right"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "or"
                      },
                      "left": {
                        "$ref": "#/definitions/__schema1"
                      },
                      "right": {
                        "$ref": "#/definitions/__schema1"
                      }
                    },
                    "required": [
                      "kind",
                      "left",
                      "right"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "allOf"
                      },
                      "operands": {
                        "type": "array",
                        "items": {
                          "$ref": "#/definitions/__schema1"
                        }
                      }
                    },
                    "required": [
                      "kind",
                      "operands"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "anyOf"
                      },
                      "operands": {
                        "type": "array",
                        "items": {
                          "$ref": "#/definitions/__schema1"
                        }
                      }
                    },
                    "required": [
                      "kind",
                      "operands"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "compare"
                      },
                      "op": {
                        "type": "string",
                        "enum": [
                          "gt",
                          "gte",
                          "lt",
                          "lte",
                          "eq",
                          "neq"
                        ]
                      },
                      "left": {
                        "$ref": "#/definitions/__schema2"
                      },
                      "right": {
                        "$ref": "#/definitions/__schema2"
                      }
                    },
                    "required": [
                      "kind",
                      "op",
                      "left",
                      "right"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "textCompare"
                      },
                      "op": {
                        "type": "string",
                        "enum": [
                          "equals",
                          "notEquals",
                          "matches",
                          "notMatches",
                          "portableMatches",
                          "portableNotMatches"
                        ]
                      },
                      "left": {
                        "$ref": "#/definitions/__schema2"
                      },
                      "right": {
                        "$ref": "#/definitions/__schema2"
                      }
                    },
                    "required": [
                      "kind",
                      "op",
                      "left",
                      "right"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "memberOf"
                      },
                      "op": {
                        "type": "string",
                        "enum": [
                          "in",
                          "notIn"
                        ]
                      },
                      "operand": {
                        "$ref": "#/definitions/__schema2"
                      },
                      "candidates": {
                        "type": "array",
                        "items": {
                          "$ref": "#/definitions/__schema2"
                        }
                      }
                    },
                    "required": [
                      "kind",
                      "op",
                      "operand",
                      "candidates"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "exists"
                      },
                      "operand": {
                        "$ref": "#/definitions/__schema2"
                      }
                    },
                    "required": [
                      "kind",
                      "operand"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "some"
                      },
                      "collection": {
                        "$ref": "#/definitions/__schema3"
                      },
                      "item": {
                        "$ref": "#/definitions/__schema1"
                      },
                      "filter": {
                        "allOf": [
                          {
                            "$ref": "#/definitions/__schema1"
                          }
                        ]
                      }
                    },
                    "required": [
                      "kind",
                      "collection",
                      "item"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "every"
                      },
                      "collection": {
                        "$ref": "#/definitions/__schema3"
                      },
                      "item": {
                        "$ref": "#/definitions/__schema1"
                      },
                      "filter": {
                        "allOf": [
                          {
                            "$ref": "#/definitions/__schema1"
                          }
                        ]
                      }
                    },
                    "required": [
                      "kind",
                      "collection",
                      "item"
                    ],
                    "additionalProperties": false
                  },
                  {
                    "type": "object",
                    "properties": {
                      "kind": {
                        "type": "string",
                        "const": "treeReference"
                      },
                      "key": {
                        "$ref": "#/definitions/__schema3"
                      }
                    },
                    "required": [
                      "kind",
                      "key"
                    ],
                    "additionalProperties": false
                  }
                ],
                "description": "A trilean predicate tree over the context. Reference keys name context fields: cwd, branch, actor, remote, env:NAME and role:NAME. An unknown field makes the result unknown, which restricts and never grants. Nodes that would read an unknown field as absent or empty (exists, some, every, fold) are not allowed.",
                "allOf": [
                  {
                    "$ref": "#/definitions/__schema1"
                  }
                ]
              }
            },
            "additionalProperties": false
          }
        },
        "required": [
          "tool",
          "tier"
        ],
        "additionalProperties": false,
        "description": "Permission rule. Evaluated deny-first: all deny rules, then ask, then allow."
      },
      "description": "Permission rules. Evaluated deny-first: all deny rules checked, then ask, then allow. Falls back to defaultMode when no rule matches."
    },
    "roles": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "pattern": "^[A-Za-z0-9_.-]+$"
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "allow": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Tools auto-approved without prompting. Evaluated after deny rules.",
            "examples": [
              "Bash(git status)",
              "Bash(npm run test:*)",
              "Read",
              "Grep"
            ]
          },
          "deny": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Tools always denied — short-circuits before allow and ask. A deny cannot be overridden by an allow in any other source.",
            "examples": [
              "Bash(sudo:*)",
              "Bash(rm -rf /)",
              "Read(./.env)"
            ]
          },
          "ask": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Tools that always prompt, even in autonomous mode. Evaluated after deny but before allow.",
            "examples": [
              "Bash(git push:*)",
              "Bash(npm publish:*)"
            ]
          }
        },
        "additionalProperties": false
      },
      "description": "Permission tiers by role. Each rule applies to actors holding the role, as if it carried `when: { role }`.",
      "examples": [
        {
          "maintainer": {
            "allow": [
              "Bash(git push:*)"
            ]
          },
          "contractor": {
            "deny": [
              "Bash(git push:*)"
            ]
          }
        }
      ]
    },
    "profiles": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "allow": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Tools auto-approved without prompting. Evaluated after deny rules.",
            "examples": [
              "Bash(git status)",
              "Bash(npm run test:*)",
              "Read",
              "Grep"
            ]
          },
          "deny": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Tools always denied — short-circuits before allow and ask. A deny cannot be overridden by an allow in any other source.",
            "examples": [
              "Bash(sudo:*)",
              "Bash(rm -rf /)",
              "Read(./.env)"
            ]
          },
          "ask": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Tools that always prompt, even in autonomous mode. Evaluated after deny but before allow.",
            "examples": [
              "Bash(git push:*)",
              "Bash(npm publish:*)"
            ]
          },
          "additionalDirectories": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Directories beyond project root that agents may access.",
            "examples": [
              "../shared-libs/",
              "/tmp/build-cache"
            ]
          },
          "defaultMode": {
            "type": "string",
            "enum": [
              "standard",
              "autonomous",
              "restricted",
              "readonly",
              "plan",
              "dontAsk",
              "acceptEdits",
              "bypassPermissions",
              "default",
              "auto"
            ],
            "description": "Default permission mode. Accepted here for Claude Code compatibility, or at the top level for the canonical placement.",
            "default": "standard"
          },
          "extends": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Names of profiles this one extends. Their rules come first, then this profile's own; extending only adds.",
            "examples": [
              [
                "base"
              ]
            ]
          }
        },
        "additionalProperties": false
      },
      "description": "Named permission profiles.",
      "examples": [
        {
          "strict": {
            "deny": [
              "Write",
              "Edit",
              "Bash"
            ],
            "allow": [
              "Read",
              "Grep"
            ]
          },
          "relaxed": {
            "allow": [
              "Read",
              "Write",
              "Edit",
              "Bash(git:*)",
              "Bash(npm:*)"
            ]
          }
        }
      ]
    },
    "delegation": {
      "type": "object",
      "properties": {
        "maxDepth": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991,
          "description": "Maximum depth of agent nesting. 0 = no subagents allowed.",
          "default": 2
        },
        "nonDelegable": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Tools that cannot be delegated to subagents. Uses the same rule syntax.",
          "examples": [
            "Bash(sudo:*)",
            "Write(./.agents/**)"
          ]
        },
        "bubbleUp": {
          "type": "boolean",
          "description": "Whether subagents can request elevated permissions from their parent.",
          "default": true
        },
        "agents": {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "type": "object",
            "properties": {
              "allow": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Tools auto-approved without prompting. Evaluated after deny rules.",
                "examples": [
                  "Bash(git status)",
                  "Bash(npm run test:*)",
                  "Read",
                  "Grep"
                ]
              },
              "deny": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Tools always denied — short-circuits before allow and ask. A deny cannot be overridden by an allow in any other source.",
                "examples": [
                  "Bash(sudo:*)",
                  "Bash(rm -rf /)",
                  "Read(./.env)"
                ]
              },
              "ask": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Tools that always prompt, even in autonomous mode. Evaluated after deny but before allow.",
                "examples": [
                  "Bash(git push:*)",
                  "Bash(npm publish:*)"
                ]
              },
              "additionalDirectories": {
                "type": "array",
                "items": {
                  "type": "string"
                },
                "description": "Directories beyond project root that agents may access.",
                "examples": [
                  "../shared-libs/",
                  "/tmp/build-cache"
                ]
              },
              "defaultMode": {
                "type": "string",
                "enum": [
                  "standard",
                  "autonomous",
                  "restricted",
                  "readonly",
                  "plan",
                  "dontAsk",
                  "acceptEdits",
                  "bypassPermissions",
                  "default",
                  "auto"
                ],
                "description": "Default permission mode. Accepted here for Claude Code compatibility, or at the top level for the canonical placement.",
                "default": "standard"
              }
            },
            "additionalProperties": false
          },
          "description": "Per-agent permission overrides. Keys are agent names or glob patterns. Values replace (not merge with) the parent policy for that agent.",
          "examples": [
            {
              "review": {
                "deny": [
                  "Write",
                  "Edit",
                  "Bash"
                ],
                "allow": [
                  "Read",
                  "Grep"
                ]
              },
              "docs": {
                "allow": [
                  "Read",
                  "Write(./docs/**)",
                  "Bash(mdbook build:*)"
                ]
              }
            }
          ]
        }
      },
      "additionalProperties": false,
      "description": "Agent delegation controls — what subagents may do."
    },
    "sandbox": {
      "type": "object",
      "properties": {
        "mode": {
          "type": "string",
          "enum": [
            "readonly",
            "workspace-write",
            "full-access"
          ],
          "description": "Sandbox isolation mode.",
          "default": "workspace-write"
        },
        "writableRoots": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Additional paths the agent may write to (beyond project root). Only meaningful when mode is `workspace-write`.",
          "examples": [
            "/tmp/build-cache",
            "../shared-libs"
          ]
        },
        "networkAccess": {
          "type": "boolean",
          "description": "Whether the agent may make network requests from within the sandbox. When false, network access is blocked at the OS level.",
          "default": true
        }
      },
      "additionalProperties": false,
      "description": "OS-level sandbox configuration."
    },
    "network": {
      "type": "object",
      "properties": {
        "enabled": {
          "type": "boolean",
          "description": "Whether network access is permitted at all. When false, WebFetch and WebSearch are denied regardless of allow rules.",
          "default": true
        },
        "domains": {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "type": "string",
            "enum": [
              "allow",
              "deny"
            ]
          },
          "description": "Domain-level allow/deny rules for HTTP(S) requests. Supplements the WebFetch(domain:...) permission rules.",
          "examples": [
            {
              "api.example.com": "allow",
              "evil.com": "deny"
            }
          ]
        }
      },
      "additionalProperties": false,
      "description": "Network access controls."
    },
    "env": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {
        "type": "string"
      },
      "description": "Environment variables injected into all agent sessions.",
      "examples": [
        {
          "NODE_ENV": "development",
          "DISABLE_TELEMETRY": "1"
        }
      ]
    },
    "with": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "claude-code",
          "codex",
          "kiro",
          "opencode",
          "crush"
        ]
      },
      "description": "Agent configs to include when loading. Only these native configs are read (plus canonical). Mutually exclusive with `without`.",
      "examples": [
        [
          "claude-code",
          "opencode"
        ]
      ]
    },
    "without": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "claude-code",
          "codex",
          "kiro",
          "opencode",
          "crush"
        ]
      },
      "description": "Agent configs to exclude when loading. Mutually exclusive with `with`.",
      "examples": [
        [
          "codex"
        ]
      ]
    },
    "up": {
      "anyOf": [
        {
          "type": "string",
          "enum": [
            "all"
          ]
        },
        {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        }
      ],
      "description": "How far to walk up the directory tree when loading configs. 'all' walks to the filesystem root. A number limits parent directories (0 = cwd only).",
      "default": "all",
      "examples": [
        "all",
        0,
        3,
        5
      ]
    },
    "sync": {
      "type": "object",
      "properties": {
        "mode": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "sync",
                "watch"
              ]
            },
            {
              "type": "boolean",
              "const": false
            }
          ],
          "description": "Sync mode. 'sync' = one-shot at startup. 'watch' = continuous via fs.watch. false = disabled.",
          "default": false
        },
        "backup": {
          "type": "boolean",
          "description": "Write .bak files before overwriting.",
          "default": false
        }
      },
      "additionalProperties": false,
      "description": "Sync configuration for the MCP server and CLI sync command."
    }
  },
  "additionalProperties": false,
  "title": "Agent Permission Policy",
  "description": "Cross-agent permission policy for AI coding agents. Defines what tools agents may use, under what conditions, and how subagents are constrained. The `with`/`without`/`up` fields control which native agent configs are discovered and merged during walk-up loading. Placed at .agents/permissions.json (team, committed) or .agents/permissions.local.json (personal, gitignored).",
  "definitions": {
    "__schema0": {
      "type": "object",
      "properties": {
        "kind": {
          "type": "string",
          "const": "not"
        },
        "operand": {
          "$ref": "#/definitions/__schema1"
        }
      },
      "required": [
        "kind",
        "operand"
      ],
      "additionalProperties": false
    },
    "__schema1": {
      "oneOf": [
        {
          "$ref": "#/definitions/__schema0"
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "and"
            },
            "left": {
              "$ref": "#/definitions/__schema1"
            },
            "right": {
              "$ref": "#/definitions/__schema1"
            }
          },
          "required": [
            "kind",
            "left",
            "right"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "or"
            },
            "left": {
              "$ref": "#/definitions/__schema1"
            },
            "right": {
              "$ref": "#/definitions/__schema1"
            }
          },
          "required": [
            "kind",
            "left",
            "right"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "allOf"
            },
            "operands": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/__schema1"
              }
            }
          },
          "required": [
            "kind",
            "operands"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "anyOf"
            },
            "operands": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/__schema1"
              }
            }
          },
          "required": [
            "kind",
            "operands"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "compare"
            },
            "op": {
              "type": "string",
              "enum": [
                "gt",
                "gte",
                "lt",
                "lte",
                "eq",
                "neq"
              ]
            },
            "left": {
              "$ref": "#/definitions/__schema2"
            },
            "right": {
              "$ref": "#/definitions/__schema2"
            }
          },
          "required": [
            "kind",
            "op",
            "left",
            "right"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "textCompare"
            },
            "op": {
              "type": "string",
              "enum": [
                "equals",
                "notEquals",
                "matches",
                "notMatches",
                "portableMatches",
                "portableNotMatches"
              ]
            },
            "left": {
              "$ref": "#/definitions/__schema2"
            },
            "right": {
              "$ref": "#/definitions/__schema2"
            }
          },
          "required": [
            "kind",
            "op",
            "left",
            "right"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "memberOf"
            },
            "op": {
              "type": "string",
              "enum": [
                "in",
                "notIn"
              ]
            },
            "operand": {
              "$ref": "#/definitions/__schema2"
            },
            "candidates": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/__schema2"
              }
            }
          },
          "required": [
            "kind",
            "op",
            "operand",
            "candidates"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "exists"
            },
            "operand": {
              "$ref": "#/definitions/__schema2"
            }
          },
          "required": [
            "kind",
            "operand"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "some"
            },
            "collection": {
              "$ref": "#/definitions/__schema3"
            },
            "item": {
              "$ref": "#/definitions/__schema1"
            },
            "filter": {
              "allOf": [
                {
                  "$ref": "#/definitions/__schema1"
                }
              ]
            }
          },
          "required": [
            "kind",
            "collection",
            "item"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "every"
            },
            "collection": {
              "$ref": "#/definitions/__schema3"
            },
            "item": {
              "$ref": "#/definitions/__schema1"
            },
            "filter": {
              "allOf": [
                {
                  "$ref": "#/definitions/__schema1"
                }
              ]
            }
          },
          "required": [
            "kind",
            "collection",
            "item"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "kind": {
              "type": "string",
              "const": "treeReference"
            },
            "key": {
              "$ref": "#/definitions/__schema3"
            }
          },
          "required": [
            "kind",
            "key"
          ],
          "additionalProperties": false
        }
      ]
    },
    "__schema2": {
      "anyOf": [
        {
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "numberLiteral"
                },
                "value": {
                  "type": "number"
                },
                "unit": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {
                    "type": "number"
                  }
                }
              },
              "required": [
                "kind",
                "value"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "textLiteral"
                },
                "value": {
                  "type": "string"
                }
              },
              "required": [
                "kind",
                "value"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "booleanLiteral"
                },
                "value": {
                  "type": "boolean"
                }
              },
              "required": [
                "kind",
                "value"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "instantLiteral"
                },
                "value": {
                  "type": "string"
                }
              },
              "required": [
                "kind",
                "value"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "durationLiteral"
                },
                "value": {
                  "type": "number"
                },
                "unit": {
                  "type": "string",
                  "enum": [
                    "ms",
                    "s",
                    "min",
                    "h",
                    "d"
                  ]
                }
              },
              "required": [
                "kind",
                "value",
                "unit"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "reference"
                },
                "key": {
                  "$ref": "#/definitions/__schema3"
                },
                "unit": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {
                    "type": "number"
                  }
                }
              },
              "required": [
                "kind",
                "key"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "arithmetic"
                },
                "op": {
                  "type": "string",
                  "enum": [
                    "add",
                    "subtract",
                    "multiply",
                    "divide",
                    "power",
                    "modulo"
                  ]
                },
                "left": {
                  "$ref": "#/definitions/__schema2"
                },
                "right": {
                  "$ref": "#/definitions/__schema2"
                }
              },
              "required": [
                "kind",
                "op",
                "left",
                "right"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "negate"
                },
                "operand": {
                  "$ref": "#/definitions/__schema2"
                }
              },
              "required": [
                "kind",
                "operand"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "call"
                },
                "fn": {
                  "type": "string"
                },
                "args": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/__schema2"
                  }
                }
              },
              "required": [
                "kind",
                "fn",
                "args"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "lookup"
                },
                "table": {
                  "$ref": "#/definitions/__schema3"
                },
                "keys": {
                  "type": "array",
                  "items": {
                    "$ref": "#/definitions/__schema2"
                  }
                }
              },
              "required": [
                "kind",
                "table",
                "keys"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "conditional"
                },
                "hitPolicy": {
                  "type": "string",
                  "enum": [
                    "first",
                    "unique"
                  ]
                },
                "cases": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "when": {
                        "$ref": "#/definitions/__schema1"
                      },
                      "then": {
                        "$ref": "#/definitions/__schema2"
                      }
                    },
                    "required": [
                      "when",
                      "then"
                    ],
                    "additionalProperties": false
                  }
                },
                "fallback": {
                  "$ref": "#/definitions/__schema2"
                }
              },
              "required": [
                "kind",
                "cases",
                "fallback"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "fold"
                },
                "collection": {
                  "$ref": "#/definitions/__schema3"
                },
                "filter": {
                  "allOf": [
                    {
                      "$ref": "#/definitions/__schema1"
                    }
                  ]
                },
                "combiner": {
                  "oneOf": [
                    {
                      "type": "object",
                      "properties": {
                        "mode": {
                          "type": "string",
                          "const": "max"
                        },
                        "item": {
                          "$ref": "#/definitions/__schema2"
                        }
                      },
                      "required": [
                        "mode",
                        "item"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "mode": {
                          "type": "string",
                          "const": "min"
                        },
                        "item": {
                          "$ref": "#/definitions/__schema2"
                        }
                      },
                      "required": [
                        "mode",
                        "item"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "object",
                      "properties": {
                        "mode": {
                          "type": "string",
                          "const": "reduce"
                        },
                        "initial": {
                          "$ref": "#/definitions/__schema2"
                        },
                        "combine": {
                          "$ref": "#/definitions/__schema2"
                        }
                      },
                      "required": [
                        "mode",
                        "initial",
                        "combine"
                      ],
                      "additionalProperties": false
                    }
                  ]
                }
              },
              "required": [
                "kind",
                "collection",
                "combiner"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "accumulator"
                }
              },
              "required": [
                "kind"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "delegate"
                },
                "system": {
                  "type": "string"
                },
                "payload": {
                  "$ref": "#/definitions/__schema3"
                }
              },
              "required": [
                "kind",
                "system",
                "payload"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "treeReference"
                },
                "key": {
                  "$ref": "#/definitions/__schema3"
                }
              },
              "required": [
                "kind",
                "key"
              ],
              "additionalProperties": false
            }
          ]
        },
        {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "complexLiteral"
                },
                "re": {
                  "type": "number"
                },
                "im": {
                  "type": "number"
                },
                "unit": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {
                    "type": "number"
                  }
                }
              },
              "required": [
                "kind",
                "re",
                "im"
              ],
              "additionalProperties": false
            },
            {
              "type": "object",
              "properties": {
                "kind": {
                  "type": "string",
                  "const": "complexLiteral"
                },
                "magnitude": {
                  "type": "number"
                },
                "phase": {
                  "type": "number"
                },
                "unit": {
                  "type": "object",
                  "propertyNames": {
                    "type": "string"
                  },
                  "additionalProperties": {
                    "type": "number"
                  }
                }
              },
              "required": [
                "kind",
                "magnitude",
                "phase"
              ],
              "additionalProperties": false
            }
          ]
        }
      ]
    },
    "__schema3": {
      "anyOf": [
        {
          "type": "string"
        },
        {
          "type": "number"
        },
        {
          "type": "boolean"
        },
        {
          "type": "null"
        },
        {
          "type": "array",
          "items": {
            "$ref": "#/definitions/__schema3"
          }
        },
        {
          "type": "object",
          "propertyNames": {
            "type": "string"
          },
          "additionalProperties": {
            "$ref": "#/definitions/__schema3"
          }
        }
      ]
    }
  }
}
