{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://denial-web.github.io/clawguard/schemas/agent-action-proposal.schema.json",
  "title": "ClawGuardAgentActionProposal",
  "type": "object",
  "required": ["tool", "args"],
  "additionalProperties": false,
  "properties": {
    "schemaVersion": {
      "type": "string",
      "const": "clawguard.agentActionProposal.v1"
    },
    "id": {
      "type": "string",
      "description": "Optional client-generated proposal id."
    },
    "source": {
      "type": "string",
      "description": "Client/source label such as termux, local-model, sidekick-bridge, or manual."
    },
    "task": {
      "type": "string",
      "description": "User-facing task the proposed action supports."
    },
    "tool": {
      "type": "string",
      "enum": [
        "file.list",
        "file.read",
        "file.diff",
        "file.write_safe",
        "project.cleanup_safe",
        "shell.dry_run",
        "shell.execute_approved",
        "skill.install_guarded",
        "git.status",
        "git.diff",
        "git.log",
        "memory.search",
        "memory.propose",
        "web.search",
        "web.fetch",
        "github.repo_read",
        "github.issue_draft",
        "github.issue_create_approved",
        "browser.open",
        "browser.extract",
        "browser.click_proposed",
        "browser.type_proposed",
        "app.open_proposed",
        "app.action_proposed",
        "subagent.delegate"
      ]
    },
    "args": {
      "type": "object",
      "description": "Tool-specific arguments."
    },
    "reason": {
      "type": "string",
      "description": "Why the model/client proposes this action."
    },
    "risk": {
      "type": "string",
      "enum": ["low", "medium", "high", "critical"]
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    }
  },
  "allOf": [
    {
      "if": { "properties": { "tool": { "const": "file.list" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "path": { "type": "string" },
              "maxDepth": { "type": "integer", "minimum": 0, "maximum": 6 },
              "maxEntries": { "type": "integer", "minimum": 1, "maximum": 1000 }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "file.read" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["path"],
            "additionalProperties": false,
            "properties": {
              "path": { "type": "string" },
              "maxBytes": { "type": "integer", "minimum": 1, "maximum": 524288 },
              "optional": { "type": "boolean" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "enum": ["file.diff", "file.write_safe"] } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["path", "content"],
            "additionalProperties": false,
            "properties": {
              "path": { "type": "string" },
              "content": { "type": "string" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "project.cleanup_safe" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "path": { "type": "string" },
              "include": {
                "type": "array",
                "items": { "type": "string" },
                "maxItems": 50
              }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "shell.dry_run" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "command": { "type": "string" },
              "argv": {
                "type": "array",
                "items": { "type": "string" },
                "minItems": 1,
                "maxItems": 32
              }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "shell.execute_approved" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["argv"],
            "additionalProperties": false,
            "properties": {
              "argv": {
                "type": "array",
                "items": { "type": "string" },
                "minItems": 1,
                "maxItems": 32
              },
              "cwd": { "type": "string" },
              "timeoutMs": { "type": "integer", "minimum": 1000, "maximum": 30000 },
              "maxBufferBytes": { "type": "integer", "minimum": 4096, "maximum": 1048576 }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "skill.install_guarded" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["source"],
            "additionalProperties": false,
            "properties": {
              "source": { "type": "string" },
              "name": { "type": "string" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "enum": ["git.status", "git.diff"] } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "path": { "type": "string" },
              "staged": { "type": "boolean" },
              "maxBytes": { "type": "integer", "minimum": 4096, "maximum": 1048576 }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "git.log" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
              "limit": { "type": "integer", "minimum": 1, "maximum": 50 }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "memory.search" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["query"],
            "additionalProperties": false,
            "properties": {
              "query": { "type": "string" },
              "limit": { "type": "integer", "minimum": 1, "maximum": 50 },
              "scope": { "type": "string" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "memory.propose" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["content"],
            "additionalProperties": false,
            "properties": {
              "type": { "type": "string" },
              "content": { "type": "string" },
              "scope": { "type": "string" },
              "sensitive": { "type": "boolean" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "web.search" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["query"],
            "additionalProperties": false,
            "properties": {
              "query": { "type": "string" },
              "limit": { "type": "integer", "minimum": 1, "maximum": 10 }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "web.fetch" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["url"],
            "additionalProperties": false,
            "properties": {
              "url": { "type": "string", "format": "uri" },
              "maxBytes": { "type": "integer", "minimum": 1, "maximum": 524288 }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "github.repo_read" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["repo"],
            "additionalProperties": false,
            "properties": {
              "repo": { "type": "string" },
              "includeIssues": { "type": "boolean" },
              "includeReleases": { "type": "boolean" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "enum": ["github.issue_draft", "github.issue_create_approved"] } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["repo", "title", "body"],
            "additionalProperties": false,
            "properties": {
              "repo": { "type": "string" },
              "title": { "type": "string" },
              "body": { "type": "string" },
              "labels": {
                "type": "array",
                "items": { "type": "string" },
                "maxItems": 20
              }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "enum": ["browser.open", "browser.extract"] } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["url"],
            "additionalProperties": false,
            "properties": {
              "url": { "type": "string", "format": "uri" },
              "selector": { "type": "string" },
              "purpose": { "type": "string" },
              "allowPrivate": { "type": "boolean" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "browser.click_proposed" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["url", "selector"],
            "additionalProperties": false,
            "properties": {
              "url": { "type": "string", "format": "uri" },
              "selector": { "type": "string" },
              "label": { "type": "string" },
              "intent": { "type": "string" },
              "purpose": { "type": "string" },
              "allowPrivate": { "type": "boolean" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "browser.type_proposed" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["url", "selector", "text"],
            "additionalProperties": false,
            "properties": {
              "url": { "type": "string", "format": "uri" },
              "selector": { "type": "string" },
              "field": { "type": "string" },
              "label": { "type": "string" },
              "name": { "type": "string" },
              "placeholder": { "type": "string" },
              "text": { "type": "string" },
              "purpose": { "type": "string" },
              "allowPrivate": { "type": "boolean" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "app.open_proposed" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["app"],
            "additionalProperties": false,
            "properties": {
              "app": { "type": "string" },
              "purpose": { "type": "string" }
            }
          }
        }
      }
    },
    {
      "if": { "properties": { "tool": { "const": "app.action_proposed" } } },
      "then": {
        "properties": {
          "args": {
            "type": "object",
            "required": ["app", "action"],
            "additionalProperties": false,
            "properties": {
              "app": { "type": "string" },
              "action": { "type": "string" },
              "target": { "type": "string" },
              "purpose": { "type": "string" }
            }
          }
        }
      }
    }
  ]
}
