{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Multi-CLI Discussion Artifact Schema",
  "description": "Visualization-friendly output for multi-CLI collaborative discussion agent",
  "type": "object",
  "required": ["metadata", "discussionTopic", "relatedFiles", "planning", "decision", "decisionRecords"],
  "properties": {
    "metadata": {
      "type": "object",
      "required": ["artifactId", "roundId", "timestamp", "contributingAgents"],
      "properties": {
        "artifactId": {
          "type": "string",
          "description": "Unique ID for this artifact (e.g., 'MCP-auth-refactor-2026-01-13-round-1')"
        },
        "roundId": {
          "type": "integer",
          "minimum": 1,
          "description": "Discussion round number"
        },
        "timestamp": {
          "type": "string",
          "format": "date-time",
          "description": "ISO 8601 timestamp"
        },
        "contributingAgents": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/AgentIdentifier"
          },
          "description": "Agents that contributed to this artifact"
        },
        "durationSeconds": {
          "type": "integer",
          "description": "Total duration in seconds"
        },
        "exportFormats": {
          "type": "array",
          "items": {
            "type": "string",
            "enum": ["markdown", "html"]
          },
          "description": "Supported export formats"
        }
      }
    },
    "discussionTopic": {
      "type": "object",
      "required": ["title", "description", "status"],
      "properties": {
        "title": {
          "$ref": "#/definitions/I18nLabel"
        },
        "description": {
          "$ref": "#/definitions/I18nLabel"
        },
        "scope": {
          "type": "object",
          "properties": {
            "included": {
              "type": "array",
              "items": { "$ref": "#/definitions/I18nLabel" },
              "description": "What's in scope"
            },
            "excluded": {
              "type": "array",
              "items": { "$ref": "#/definitions/I18nLabel" },
              "description": "What's explicitly out of scope"
            }
          }
        },
        "keyQuestions": {
          "type": "array",
          "items": { "$ref": "#/definitions/I18nLabel" },
          "description": "Questions being explored"
        },
        "status": {
          "type": "string",
          "enum": ["exploring", "analyzing", "debating", "decided", "blocked"],
          "description": "Discussion status"
        },
        "tags": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Tags for filtering (e.g., ['auth', 'security', 'api'])"
        }
      }
    },
    "relatedFiles": {
      "type": "object",
      "properties": {
        "fileTree": {
          "type": "array",
          "items": { "$ref": "#/definitions/FileNode" },
          "description": "File tree structure"
        },
        "dependencyGraph": {
          "type": "array",
          "items": { "$ref": "#/definitions/DependencyEdge" },
          "description": "Dependency relationships"
        },
        "impactSummary": {
          "type": "array",
          "items": { "$ref": "#/definitions/FileImpact" },
          "description": "File impact summary"
        }
      }
    },
    "planning": {
      "type": "object",
      "properties": {
        "functional": {
          "type": "array",
          "items": { "$ref": "#/definitions/Requirement" },
          "description": "Functional requirements"
        },
        "nonFunctional": {
          "type": "array",
          "items": { "$ref": "#/definitions/Requirement" },
          "description": "Non-functional requirements"
        },
        "acceptanceCriteria": {
          "type": "array",
          "items": { "$ref": "#/definitions/AcceptanceCriterion" },
          "description": "Acceptance criteria"
        }
      }
    },
    "decision": {
      "type": "object",
      "required": ["status", "confidenceScore"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["pending", "decided", "conflict"],
          "description": "Decision status"
        },
        "summary": {
          "$ref": "#/definitions/I18nLabel"
        },
        "selectedSolution": {
          "$ref": "#/definitions/Solution"
        },
        "rejectedAlternatives": {
          "type": "array",
          "items": { "$ref": "#/definitions/RejectedSolution" }
        },
        "confidenceScore": {
          "type": "number",
          "minimum": 0,
          "maximum": 1,
          "description": "Confidence score (0.0 to 1.0)"
        }
      }
    },
    "decisionRecords": {
      "type": "object",
      "properties": {
        "timeline": {
          "type": "array",
          "items": { "$ref": "#/definitions/DecisionEvent" },
          "description": "Timeline of decision events"
        }
      }
    },
    "_internal": {
      "type": "object",
      "description": "Internal analysis data (for debugging)",
      "properties": {
        "cli_analyses": {
          "type": "array",
          "items": { "$ref": "#/definitions/CLIAnalysis" }
        },
        "cross_verification": {
          "$ref": "#/definitions/CrossVerification"
        },
        "convergence": {
          "$ref": "#/definitions/ConvergenceMetrics"
        }
      }
    }
  },
  "definitions": {
    "I18nLabel": {
      "type": "object",
      "required": ["en", "zh"],
      "properties": {
        "en": { "type": "string" },
        "zh": { "type": "string" }
      },
      "description": "Multi-language label for UI display"
    },
    "AgentIdentifier": {
      "type": "object",
      "required": ["name", "id"],
      "properties": {
        "name": {
          "type": "string",
          "enum": ["Gemini", "Codex", "Qwen", "Human", "System"]
        },
        "id": { "type": "string" }
      }
    },
    "FileNode": {
      "type": "object",
      "required": ["path", "type"],
      "properties": {
        "path": { "type": "string" },
        "type": {
          "type": "string",
          "enum": ["file", "directory"]
        },
        "modificationStatus": {
          "type": "string",
          "enum": ["added", "modified", "deleted", "unchanged"]
        },
        "impactScore": {
          "type": "string",
          "enum": ["critical", "high", "medium", "low"]
        },
        "children": {
          "type": "array",
          "items": { "$ref": "#/definitions/FileNode" }
        },
        "codeSnippet": { "$ref": "#/definitions/CodeSnippet" }
      }
    },
    "DependencyEdge": {
      "type": "object",
      "required": ["source", "target", "relationship"],
      "properties": {
        "source": { "type": "string" },
        "target": { "type": "string" },
        "relationship": { "type": "string" }
      }
    },
    "FileImpact": {
      "type": "object",
      "required": ["filePath", "score", "reasoning"],
      "properties": {
        "filePath": { "type": "string" },
        "line": { "type": "integer" },
        "score": {
          "type": "string",
          "enum": ["critical", "high", "medium", "low"]
        },
        "reasoning": { "$ref": "#/definitions/I18nLabel" }
      }
    },
    "CodeSnippet": {
      "type": "object",
      "required": ["startLine", "endLine", "code"],
      "properties": {
        "startLine": { "type": "integer" },
        "endLine": { "type": "integer" },
        "code": { "type": "string" },
        "language": { "type": "string" },
        "comment": { "$ref": "#/definitions/I18nLabel" }
      }
    },
    "Requirement": {
      "type": "object",
      "required": ["id", "description", "priority"],
      "properties": {
        "id": { "type": "string" },
        "description": { "$ref": "#/definitions/I18nLabel" },
        "priority": {
          "type": "string",
          "enum": ["critical", "high", "medium", "low"]
        },
        "source": { "type": "string" }
      }
    },
    "AcceptanceCriterion": {
      "type": "object",
      "required": ["id", "description", "isMet"],
      "properties": {
        "id": { "type": "string" },
        "description": { "$ref": "#/definitions/I18nLabel" },
        "isMet": { "type": "boolean" }
      }
    },
    "Solution": {
      "type": "object",
      "required": ["id", "title", "description"],
      "properties": {
        "id": { "type": "string" },
        "title": { "$ref": "#/definitions/I18nLabel" },
        "description": { "$ref": "#/definitions/I18nLabel" },
        "pros": {
          "type": "array",
          "items": { "$ref": "#/definitions/I18nLabel" }
        },
        "cons": {
          "type": "array",
          "items": { "$ref": "#/definitions/I18nLabel" }
        },
        "estimatedEffort": { "$ref": "#/definitions/I18nLabel" },
        "risk": {
          "type": "string",
          "enum": ["critical", "high", "medium", "low"]
        },
        "affectedFiles": {
          "type": "array",
          "items": { "$ref": "#/definitions/FileImpact" }
        },
        "sourceCLIs": {
          "type": "array",
          "items": { "type": "string" }
        }
      }
    },
    "RejectedSolution": {
      "allOf": [
        { "$ref": "#/definitions/Solution" },
        {
          "type": "object",
          "required": ["rejectionReason"],
          "properties": {
            "rejectionReason": { "$ref": "#/definitions/I18nLabel" }
          }
        }
      ]
    },
    "DecisionEvent": {
      "type": "object",
      "required": ["eventId", "timestamp", "type", "contributor", "summary"],
      "properties": {
        "eventId": { "type": "string" },
        "timestamp": {
          "type": "string",
          "format": "date-time"
        },
        "type": {
          "type": "string",
          "enum": ["proposal", "argument", "agreement", "disagreement", "decision", "reversal"]
        },
        "contributor": { "$ref": "#/definitions/AgentIdentifier" },
        "summary": { "$ref": "#/definitions/I18nLabel" },
        "evidence": {
          "type": "array",
          "items": { "$ref": "#/definitions/Evidence" }
        },
        "reversibility": {
          "type": "string",
          "enum": ["easily_reversible", "requires_refactoring", "irreversible"]
        }
      }
    },
    "Evidence": {
      "type": "object",
      "required": ["type", "content", "description"],
      "properties": {
        "type": {
          "type": "string",
          "enum": ["link", "code_snippet", "log_output", "benchmark", "reference"]
        },
        "content": {},
        "description": { "$ref": "#/definitions/I18nLabel" }
      }
    },
    "CLIAnalysis": {
      "type": "object",
      "required": ["tool", "perspective", "feasibility_score"],
      "properties": {
        "tool": {
          "type": "string",
          "enum": ["gemini", "codex", "qwen"]
        },
        "perspective": { "type": "string" },
        "feasibility_score": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "findings": {
          "type": "array",
          "items": { "type": "string" }
        },
        "implementation_approaches": { "type": "array" },
        "technical_concerns": {
          "type": "array",
          "items": { "type": "string" }
        },
        "code_locations": {
          "type": "array",
          "items": { "$ref": "#/definitions/FileImpact" }
        }
      }
    },
    "CrossVerification": {
      "type": "object",
      "properties": {
        "agreements": {
          "type": "array",
          "items": { "type": "string" }
        },
        "disagreements": {
          "type": "array",
          "items": { "type": "string" }
        },
        "resolution": { "type": "string" }
      }
    },
    "ConvergenceMetrics": {
      "type": "object",
      "properties": {
        "score": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "new_insights": { "type": "boolean" },
        "recommendation": {
          "type": "string",
          "enum": ["continue", "converged", "user_input_needed"]
        }
      }
    }
  }
}
