{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://skills.pixmoving.com/cognitive-boundary/schemas/install-result.schema.json",
  "title": "Cognitive Boundary Breaker installation result",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "protocol",
    "state",
    "final_status",
    "user_intent",
    "platform",
    "selection",
    "plan",
    "authorization",
    "execution",
    "verification",
    "rollback",
    "warnings",
    "next_actions"
  ],
  "properties": {
    "protocol": {
      "const": "cbb-install/1.0"
    },
    "state": {
      "enum": [
        "SUCCEEDED",
        "PARTIAL",
        "BLOCKED",
        "FAILED",
        "CANCELLED"
      ]
    },
    "final_status": {
      "enum": [
        "installed_verified",
        "installed_unverified",
        "guided_pending_user",
        "partially_verified",
        "blocked",
        "failed",
        "cancelled"
      ]
    },
    "user_intent": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "basis",
        "evidence"
      ],
      "properties": {
        "mode": {
          "const": "install"
        },
        "basis": {
          "enum": [
            "explicit",
            "clarified"
          ]
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "platform": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "name",
        "basis",
        "evidence"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "basis": {
          "enum": [
            "observed",
            "user_stated",
            "unknown"
          ]
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "selection": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "mode",
        "reason",
        "fallback"
      ],
      "properties": {
        "mode": {
          "enum": [
            "openai_standalone_skill",
            "claude_skill_upload",
            "kimi_code_local_skill",
            "kimi_agent_authoring",
            "project_instructions",
            "conversation_opener",
            "api_provider_adapter"
          ]
        },
        "reason": {
          "type": "string",
          "minLength": 1
        },
        "fallback": {
          "type": [
            "string",
            "null"
          ],
          "enum": [
            "openai_standalone_skill",
            "claude_skill_upload",
            "kimi_code_local_skill",
            "kimi_agent_authoring",
            "project_instructions",
            "conversation_opener",
            "api_provider_adapter",
            null
          ]
        }
      }
    },
    "plan": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "digest_sha256",
        "presented_to_user",
        "target",
        "artifact",
        "mutations",
        "required_permissions",
        "verification_steps",
        "rollback_steps"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[A-Za-z0-9._-]{8,128}$"
        },
        "digest_sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "presented_to_user": {
          "const": true
        },
        "target": {
          "type": "string",
          "minLength": 1
        },
        "artifact": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "id",
            "version",
            "sha256"
          ],
          "properties": {
            "id": {
              "type": "string",
              "minLength": 1
            },
            "version": {
              "type": "string",
              "minLength": 1
            },
            "sha256": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            }
          }
        },
        "mutations": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "required_permissions": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "verification_steps": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "rollback_steps": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "authorization": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "bound_to_presented_plan",
        "granted_at",
        "scope",
        "evidence"
      ],
      "properties": {
        "status": {
          "enum": [
            "awaiting",
            "granted",
            "denied"
          ]
        },
        "bound_to_presented_plan": {
          "type": "boolean"
        },
        "granted_at": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time"
        },
        "scope": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "execution": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "followed_presented_plan",
        "artifact_integrity",
        "target_shown_to_user",
        "transmitted_to_site",
        "evidence"
      ],
      "properties": {
        "status": {
          "enum": [
            "not_run",
            "completed",
            "partial",
            "failed"
          ]
        },
        "followed_presented_plan": {
          "type": "boolean"
        },
        "artifact_integrity": {
          "enum": [
            "not_checked",
            "matched_to_plan",
            "mismatched"
          ]
        },
        "target_shown_to_user": {
          "type": "string",
          "minLength": 1
        },
        "transmitted_to_site": {
          "const": false
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "verification": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "highest_stage",
        "context",
        "checks"
      ],
      "properties": {
        "status": {
          "enum": [
            "passed",
            "partial",
            "not_run",
            "failed"
          ]
        },
        "highest_stage": {
          "enum": [
            "discovered",
            "integrity_checked",
            "written_or_uploaded",
            "registered_or_enabled",
            "loaded",
            "behavior_verified"
          ]
        },
        "context": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "fresh_context",
            "source_page_absent",
            "bound_to_presented_plan",
            "activation_evidence"
          ],
          "properties": {
            "fresh_context": {
              "type": "boolean"
            },
            "source_page_absent": {
              "type": "boolean"
            },
            "bound_to_presented_plan": {
              "type": "boolean"
            },
            "activation_evidence": {
              "type": "array",
              "items": {
                "type": "string",
                "minLength": 1
              }
            }
          }
        },
        "checks": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "status",
              "evidence"
            ],
            "properties": {
              "id": {
                "enum": [
                  "target_configuration",
                  "artifact_integrity",
                  "skill_loaded",
                  "positive_probe",
                  "non_trigger_probe",
                  "protocol_semantics"
                ]
              },
              "status": {
                "enum": [
                  "passed",
                  "failed",
                  "not_run"
                ]
              },
              "evidence": {
                "type": "array",
                "minItems": 1,
                "uniqueItems": true,
                "items": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          }
        }
      }
    },
    "rollback": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "plan",
        "evidence"
      ],
      "properties": {
        "status": {
          "enum": [
            "available",
            "performed",
            "failed",
            "not_needed"
          ]
        },
        "plan": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "evidence": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
            "type": "string",
            "minLength": 1
          }
        }
      }
    },
    "warnings": {
      "type": "array",
      "items": {
        "type": "string",
        "minLength": 1
      }
    },
    "next_actions": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 1
      }
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "final_status": {
            "const": "installed_verified"
          }
        },
        "required": [
          "final_status"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "SUCCEEDED"
          },
          "platform": {
            "properties": {
              "basis": {
                "const": "observed"
              },
              "evidence": {
                "minItems": 1
              }
            }
          },
          "authorization": {
            "properties": {
              "status": {
                "const": "granted"
              },
              "bound_to_presented_plan": {
                "const": true
              },
              "granted_at": {
                "type": "string"
              },
              "scope": {
                "minItems": 1
              },
              "evidence": {
                "minItems": 1
              }
            }
          },
          "execution": {
            "properties": {
              "status": {
                "const": "completed"
              },
              "followed_presented_plan": {
                "const": true
              },
              "artifact_integrity": {
                "const": "matched_to_plan"
              },
              "evidence": {
                "minItems": 1
              }
            }
          },
          "verification": {
            "properties": {
              "status": {
                "const": "passed"
              },
              "highest_stage": {
                "const": "behavior_verified"
              },
              "context": {
                "properties": {
                  "fresh_context": {
                    "const": true
                  },
                  "source_page_absent": {
                    "const": true
                  },
                  "bound_to_presented_plan": {
                    "const": true
                  },
                  "activation_evidence": {
                    "minItems": 1
                  }
                }
              },
              "checks": {
                "minItems": 6,
                "maxItems": 6,
                "items": {
                  "properties": {
                    "status": {
                      "const": "passed"
                    }
                  }
                },
                "allOf": [
                  {
                    "contains": {
                      "properties": {
                        "id": {
                          "const": "target_configuration"
                        }
                      },
                      "required": [
                        "id"
                      ]
                    },
                    "minContains": 1,
                    "maxContains": 1
                  },
                  {
                    "contains": {
                      "properties": {
                        "id": {
                          "const": "artifact_integrity"
                        }
                      },
                      "required": [
                        "id"
                      ]
                    },
                    "minContains": 1,
                    "maxContains": 1
                  },
                  {
                    "contains": {
                      "properties": {
                        "id": {
                          "const": "skill_loaded"
                        }
                      },
                      "required": [
                        "id"
                      ]
                    },
                    "minContains": 1,
                    "maxContains": 1
                  },
                  {
                    "contains": {
                      "properties": {
                        "id": {
                          "const": "positive_probe"
                        }
                      },
                      "required": [
                        "id"
                      ]
                    },
                    "minContains": 1,
                    "maxContains": 1
                  },
                  {
                    "contains": {
                      "properties": {
                        "id": {
                          "const": "non_trigger_probe"
                        }
                      },
                      "required": [
                        "id"
                      ]
                    },
                    "minContains": 1,
                    "maxContains": 1
                  },
                  {
                    "contains": {
                      "properties": {
                        "id": {
                          "const": "protocol_semantics"
                        }
                      },
                      "required": [
                        "id"
                      ]
                    },
                    "minContains": 1,
                    "maxContains": 1
                  }
                ]
              }
            }
          },
          "rollback": {
            "properties": {
              "status": {
                "enum": [
                  "available",
                  "performed"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "final_status": {
            "const": "installed_unverified"
          }
        },
        "required": [
          "final_status"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "PARTIAL"
          },
          "authorization": {
            "properties": {
              "status": {
                "const": "granted"
              },
              "bound_to_presented_plan": {
                "const": true
              },
              "granted_at": {
                "type": "string"
              }
            }
          },
          "execution": {
            "properties": {
              "status": {
                "const": "completed"
              },
              "followed_presented_plan": {
                "const": true
              },
              "artifact_integrity": {
                "const": "matched_to_plan"
              }
            }
          },
          "verification": {
            "properties": {
              "status": {
                "enum": [
                  "partial",
                  "not_run"
                ]
              },
              "highest_stage": {
                "enum": [
                  "written_or_uploaded",
                  "registered_or_enabled",
                  "loaded"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "final_status": {
            "const": "guided_pending_user"
          }
        },
        "required": [
          "final_status"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "PARTIAL"
          },
          "authorization": {
            "properties": {
              "status": {
                "const": "awaiting"
              },
              "bound_to_presented_plan": {
                "const": false
              },
              "granted_at": {
                "type": "null"
              }
            }
          },
          "execution": {
            "properties": {
              "status": {
                "const": "not_run"
              },
              "followed_presented_plan": {
                "const": false
              }
            }
          },
          "verification": {
            "properties": {
              "status": {
                "const": "not_run"
              },
              "highest_stage": {
                "enum": [
                  "discovered",
                  "integrity_checked"
                ]
              },
              "context": {
                "properties": {
                  "bound_to_presented_plan": {
                    "const": false
                  }
                }
              },
              "checks": {
                "maxItems": 0
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "final_status": {
            "const": "partially_verified"
          }
        },
        "required": [
          "final_status"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "PARTIAL"
          },
          "authorization": {
            "properties": {
              "status": {
                "const": "granted"
              },
              "bound_to_presented_plan": {
                "const": true
              }
            }
          },
          "execution": {
            "properties": {
              "status": {
                "enum": [
                  "completed",
                  "partial"
                ]
              },
              "followed_presented_plan": {
                "const": true
              },
              "artifact_integrity": {
                "const": "matched_to_plan"
              }
            }
          },
          "verification": {
            "properties": {
              "status": {
                "const": "partial"
              },
              "highest_stage": {
                "enum": [
                  "written_or_uploaded",
                  "registered_or_enabled",
                  "loaded"
                ]
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "final_status": {
            "const": "blocked"
          }
        },
        "required": [
          "final_status"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "BLOCKED"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "final_status": {
            "const": "failed"
          }
        },
        "required": [
          "final_status"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "FAILED"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "final_status": {
            "const": "cancelled"
          }
        },
        "required": [
          "final_status"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "CANCELLED"
          },
          "authorization": {
            "properties": {
              "status": {
                "const": "denied"
              },
              "bound_to_presented_plan": {
                "const": false
              },
              "granted_at": {
                "type": "null"
              }
            }
          },
          "execution": {
            "properties": {
              "status": {
                "const": "not_run"
              },
              "followed_presented_plan": {
                "const": false
              }
            }
          },
          "verification": {
            "properties": {
              "status": {
                "const": "not_run"
              },
              "highest_stage": {
                "enum": [
                  "discovered",
                  "integrity_checked"
                ]
              },
              "context": {
                "properties": {
                  "bound_to_presented_plan": {
                    "const": false
                  }
                }
              },
              "checks": {
                "maxItems": 0
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "authorization": {
            "properties": {
              "status": {
                "const": "denied"
              }
            },
            "required": [
              "status"
            ]
          }
        },
        "required": [
          "authorization"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "CANCELLED"
          },
          "final_status": {
            "const": "cancelled"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "verification": {
            "properties": {
              "status": {
                "const": "failed"
              }
            },
            "required": [
              "status"
            ]
          }
        },
        "required": [
          "verification"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "FAILED"
          },
          "final_status": {
            "const": "failed"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "execution": {
            "properties": {
              "status": {
                "const": "failed"
              }
            },
            "required": [
              "status"
            ]
          }
        },
        "required": [
          "execution"
        ]
      },
      "then": {
        "properties": {
          "state": {
            "const": "FAILED"
          },
          "final_status": {
            "const": "failed"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "state": {
            "const": "SUCCEEDED"
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "properties": {
          "final_status": {
            "const": "installed_verified"
          }
        }
      }
    }
  ]
}
