{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://github.com/multi-agent-ecosystem/multi-agent-pipeline/pipeline/schemas/unattended-profile.schema.json",
  "title": "Unattended settings profile",
  "description": "The permission profile the installer writes for unattended runs: the default mode, the allow and deny rules, the toolkit environment and the optional sandbox, each rule with the reason it exists.",
  "type": "object",
  "additionalProperties": false,
  "required": ["defaultMode", "wideAllows", "allow", "deny", "env", "sandbox"],
  "$defs": {
    "ruleWithReason": {
      "type": "array",
      "prefixItems": [
        {
          "type": "string",
          "minLength": 1
        },
        {
          "type": "string",
          "minLength": 1
        }
      ],
      "minItems": 2,
      "maxItems": 2
    }
  },
  "properties": {
    "$comment": {
      "type": "string"
    },
    "defaultMode": {
      "type": "object",
      "additionalProperties": false,
      "required": ["value", "why"],
      "properties": {
        "value": {
          "type": "string"
        },
        "why": {
          "type": "string"
        }
      }
    },
    "wideAllows": {
      "type": "array",
      "description": "Allow rules in the attended settings that would let every call through; reported, never removed.",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["rule", "why"],
        "properties": {
          "rule": {
            "type": "string"
          },
          "why": {
            "type": "string"
          }
        }
      }
    },
    "allow": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ruleWithReason"
      }
    },
    "deny": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/ruleWithReason"
      }
    },
    "env": {
      "type": "array",
      "description": "[name, value, reason] for each variable the unattended child receives.",
      "items": {
        "type": "array",
        "prefixItems": [
          {
            "type": "string",
            "pattern": "^[A-Z][A-Z0-9_]*$"
          },
          {
            "type": "string"
          },
          {
            "type": "string",
            "minLength": 1
          }
        ],
        "minItems": 3,
        "maxItems": 3
      }
    },
    "gradleRunHome": {
      "type": "object",
      "description": "Where each run's own Gradle user home is placed. Not written into the profile: the runner and the office make it before each launch and set it in the launch environment.",
      "additionalProperties": false,
      "required": ["parent", "why"],
      "properties": {
        "parent": { "type": "string", "pattern": "^~/" },
        "why": { "type": "string", "minLength": 1 }
      }
    },
    "sandbox": {
      "type": "object",
      "additionalProperties": false,
      "required": ["enabled"],
      "properties": {
        "$comment": {
          "type": "string"
        },
        "enabled": {
          "type": "boolean"
        },
        "failIfUnavailable": {
          "type": "boolean"
        },
        "allowUnsandboxedCommands": {
          "type": "boolean"
        },
        "network": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "allowedDomains": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "deniedDomains": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "strictAllowlist": {
              "type": "boolean"
            },
            "allowManagedDomainsOnly": {
              "type": "boolean"
            },
            "allowLocalBinding": {
              "type": "boolean"
            },
            "allowMachLookup": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        },
        "filesystem": {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "denyRead": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "allowWrite": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "denyWrite": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "allowRead": {
              "type": "array",
              "items": {
                "type": "string"
              }
            },
            "disabled": {
              "type": "boolean"
            }
          }
        },
        "autoAllowBashIfSandboxed": {
          "type": "boolean"
        },
        "enableWeakerNetworkIsolation": {
          "type": "boolean"
        },
        "allowAppleEvents": {
          "type": "boolean"
        },
        "enableWeakerNestedSandbox": {
          "type": "boolean"
        },
        "excludedCommands": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      }
    }
  }
}
