{
  "rootib": "RootIB: RB-20260304173933-DS000001",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://barbrickdesign.github.io/deepsoil/schemas/tool.manifest.schema.json",
  "title": "DeepSoil Tool Manifest",
  "description": "Schema for tool entries in the DeepSoil substrate. Every tool MUST map to a RootIB tool identity, carry lineage anchors, include blessing metadata, and follow RootIB governance and revocation rules. RootIB is the authoritative identity and governance layer; DeepSoil stores and indexes the entry.",
  "type": "object",
  "required": [
    "tool_mint",
    "name",
    "version",
    "description",
    "capabilities",
    "safety_level",
    "rootib",
    "rootib_lineage",
    "rootib_blessing",
    "deepsoil_meta"
  ],
  "properties": {
    "tool_mint": {
      "type": "string",
      "description": "Solana mint address that serves as the globally unique key for this tool in DeepSoil.",
      "examples": ["TOOLMint111111111111111111111111111111111"]
    },
    "name": {
      "type": "string",
      "description": "Namespaced tool name. Convention: '<substrate>.<domain>.<verb>'.",
      "minLength": 1,
      "maxLength": 256,
      "examples": ["soil.summarize.text", "soil.agent.planner"]
    },
    "version": {
      "type": "string",
      "description": "Semantic version of this tool.",
      "pattern": "^\\d+\\.\\d+\\.\\d+(-[a-z0-9.]+)?$",
      "examples": ["1.0.0", "0.2.1-beta"]
    },
    "description": {
      "type": "string",
      "description": "Human-readable description of what this tool does.",
      "minLength": 1
    },
    "capabilities": {
      "type": "array",
      "description": "Semantic capability tags that describe what this tool can do. Used by agents for discovery.",
      "items": { "type": "string" },
      "minItems": 1,
      "examples": [["summarization", "compression"], ["plan", "decompose_tasks"]]
    },
    "inputs": {
      "type": "array",
      "description": "Input parameter definitions.",
      "items": {
        "type": "object",
        "required": ["name", "type"],
        "properties": {
          "name":        { "type": "string" },
          "type":        { "type": "string" },
          "required":    { "type": "boolean" },
          "default":     {},
          "description": { "type": "string" }
        }
      }
    },
    "outputs": {
      "type": "array",
      "description": "Output parameter definitions.",
      "items": {
        "type": "object",
        "required": ["name", "type"],
        "properties": {
          "name":        { "type": "string" },
          "type":        { "type": "string" },
          "description": { "type": "string" }
        }
      }
    },
    "invocation": {
      "type": "object",
      "description": "Describes how to call this tool.",
      "properties": {
        "kind":     { "type": "string", "enum": ["http", "solana", "wasm", "local"] },
        "endpoint": { "type": "string", "format": "uri" },
        "method":   { "type": "string", "enum": ["GET", "POST", "PUT", "PATCH"] },
        "auth":     { "type": "string", "examples": ["bearer_or_wallet_signature", "none"] }
      }
    },
    "safety_level": {
      "type": "string",
      "description": "Controls who can discover and invoke this tool. 'open' = anyone; 'restricted' = allowlist; 'blessed_only' = requires RootIB blessing.",
      "enum": ["open", "restricted", "blessed_only"],
      "default": "open"
    },
    "rootib": {
      "type": "string",
      "description": "RootIB identity string for this tool. Format: 'RootIB: <CreatorID>-<YYYYMMDDHHmmss>-<8HEX>'. Timestamps are 14 digits (YYYYMMDDHHmmss, v1.3 legacy) or 17 digits (YYYYMMDDHHmmssSSS, v1.4+ ms-precision). This is the authoritative provenance anchor issued by the tool creator. Required for all DeepSoil entries.",
      "pattern": "^RootIB: [A-Za-z0-9_.-]{1,64}-\\d{14,17}-[0-9A-Fa-f]{8}$"
    },
    "rootib_lineage": {
      "type": "object",
      "description": "RootIB lineage anchor. References the chain of provenance from genesis to this tool. Validated by RootIB; stored by DeepSoil.",
      "required": ["lineage_root"],
      "properties": {
        "lineage_root": {
          "type": "string",
          "description": "The RootIB identity at the root of this tool's lineage chain.",
          "pattern": "^RootIB: [A-Za-z0-9_.-]{1,64}-\\d{14,17}-[0-9A-Fa-f]{8}$"
        },
        "parent_rootib": {
          "type": ["string", "null"],
          "description": "RootIB identity of the direct parent entry in the lineage chain.",
          "pattern": "^RootIB: [A-Za-z0-9_.-]{1,64}-\\d{14,17}-[0-9A-Fa-f]{8}$"
        },
        "idea_root": {
          "type": "string",
          "description": "idea_id of the rooted idea this tool implements or derives from.",
          "examples": ["idea:rooted-summarization"]
        },
        "derived_from": {
          "type": "array",
          "description": "List of tool_mint or idea_id values this tool is derived from.",
          "items": { "type": "string" }
        },
        "parents": {
          "type": "array",
          "description": "Ordered list of parent RootIB identities from genesis to direct parent.",
          "items": {
            "type": "string",
            "pattern": "^RootIB: [A-Za-z0-9_.-]{1,64}-\\d{14,17}-[0-9A-Fa-f]{8}$"
          }
        }
      },
      "additionalProperties": false
    },
    "rootib_blessing": {
      "type": "object",
      "description": "RootIB blessing metadata. RootIB enforces blessing trees; tools without required blessings may be blocked from activation.",
      "required": ["blessed", "blessings"],
      "properties": {
        "blessed": {
          "type": "boolean",
          "description": "Whether this tool has received at least one active blessing."
        },
        "blessings": {
          "type": "array",
          "description": "Array of active blessing identifiers granted to this tool.",
          "items": { "type": "string" }
        },
        "blessed_by": {
          "type": "string",
          "description": "CreatorID of the RootIB identity that issued the blessing."
        },
        "blessed_at": {
          "type": "string",
          "format": "date-time",
          "description": "ISO-8601 timestamp when the blessing was granted."
        },
        "revoked": {
          "type": "boolean",
          "description": "Whether all blessings have been revoked. A revoked tool MUST NOT be invoked.",
          "default": false
        },
        "revoked_at": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "ISO-8601 timestamp when the tool was revoked."
        }
      },
      "additionalProperties": false
    },
    "governance": {
      "type": "object",
      "description": "Governance metadata. All models must follow RootIB rules. DeepSoil stores this metadata; RootIB enforces it.",
      "properties": {
        "owner":     { "type": "string", "description": "Solana pubkey of the tool owner." },
        "model":     { "type": "string", "enum": ["single_owner", "multisig", "dao"] },
        "revocable": { "type": "boolean", "default": true }
      }
    },
    "deepsoil_meta": {
      "type": "object",
      "description": "DeepSoil storage metadata.",
      "required": ["program_id", "entry_type"],
      "properties": {
        "program_id":      { "type": "string", "default": "DEEPSOiL111111111111111111111111111111111" },
        "entry_type":      { "type": "string", "const": "tool" },
        "schema_version":  { "type": "string", "default": "1.0.0" },
        "network":         { "type": "string", "enum": ["solana-mainnet", "solana-devnet", "solana-localnet", "solana-simulated"], "default": "solana-simulated" },
        "pda_seed":        { "type": "string" },
        "manifest_uri":    { "type": "string", "format": "uri" }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": true
}
