# Consensus Calculation Skill Configuration
# Standard YAML format for agentskills.io

name: "consensus-calculation"
version: "1.0.0"
description: "Calculates consensus among multiple agents using various algorithms"

metadata:
  category: "analysis"
  tags: ["consensus", "voting", "decision-making", "multi-agent"]
  author: "DAIP-LIVE Team"
  license: "MIT"
  homepage: "https://github.com/daip-live/daip-live-opencode-plugin"

execution:
  type: "script"
  language: "javascript"
  path: "./consensus-skill.js"
  function: "calculateVotingConsensus"
  timeout: 30000  # 30 seconds timeout

parameters:
  messages:
    type: "array"
    description: "Array of messages from agents containing votes or positions"
    required: true
    items:
      type: "object"
      properties:
        agent_name:
          type: "string"
          description: "Name of the agent providing the message"
        content:
          type: "string"
          description: "Content of the message, may contain vote information"
  
  algorithm:
    type: "string"
    description: "Consensus algorithm to use"
    enum: ["voting", "deliberation", "weighted"]
    default: "voting"
    required: false
  
  threshold:
    type: "number"
    description: "Minimum agreement ratio required for consensus (0-1)"
    minimum: 0
    maximum: 1
    default: 0.7
    required: false
  
  max_rounds:
    type: "number"
    description: "Maximum rounds for deliberation algorithm"
    minimum: 1
    default: 10
    required: false

input_format:
  type: "json"
  schema:
    type: "object"
    properties:
      messages:
        type: "array"
        items:
          type: "object"
          properties:
            agent_name: { type: "string" }
            content: { type: "string" }
          required: ["agent_name", "content"]
      algorithm: { type: "string", enum: ["voting", "deliberation", "weighted"] }
      threshold: { type: "number", minimum: 0, maximum: 1 }
      max_rounds: { type: "number", minimum: 1 }
    required: ["messages"]

output_format:
  type: "json"
  schema:
    type: "object"
    properties:
      achieved:
        type: "boolean"
        description: "Whether consensus was achieved"
      agreement_ratio:
        type: "number"
        description: "Ratio of agreement (0-1)"
      summary:
        type: "string"
        description: "Human-readable summary of the consensus calculation"
      votes:
        type: "object"
        description: "Detailed vote information (for voting algorithms)"
    required: ["achieved", "agreement_ratio", "summary"]

triggers:
  - condition: "user requests consensus calculation"
    context: ["multi-agent discussion", "voting scenario", "decision making"]
    frequency: "as needed"

dependencies:
  - name: "node"
    version: ">=18.0.0"
    optional: false

environments:
  - name: "nodejs"
    version: ">=18.0.0"
  - name: "bun"
    version: ">=1.0.0"
  - name: "deno"
    version: ">=1.30.0"

examples:
  - name: "simple-voting"
    description: "Calculate simple voting consensus"
    input:
      messages: 
        - { agent_name: "proponent", content: "vote: yes" }
        - { agent_name: "opponent", content: "vote: no" }
        - { agent_name: "moderator", content: "vote: yes" }
      algorithm: "voting"
      threshold: 0.6
    output:
      achieved: true
      agreement_ratio: 0.6667
      summary: "Voting Consensus (threshold: 60%)..."
      votes: 
        proponent: true
        opponent: false
        moderator: true

  - name: "deliberation-consensus"
    description: "Calculate deliberation consensus over multiple rounds"
    input:
      messages: 
        - { agent_name: "agent1", content: "round: 1, stance: support" }
        - { agent_name: "agent2", content: "round: 1, stance: oppose" }
      algorithm: "deliberation"
      max_rounds: 5
      threshold: 0.8
    output:
      achieved: false
      agreement_ratio: 0.3
      summary: "Deliberation Consensus..."
      convergence_history: [0.3]

error_handling:
  - error_type: "invalid_input"
    description: "When input doesn't match expected schema"
    recovery: "Return error message with expected format"
  - error_type: "no_votes_found"
    description: "When no votes can be extracted from messages"
    recovery: "Return consensus result with 0 agreement ratio"
  - error_type: "unsupported_algorithm"
    description: "When an unsupported algorithm is specified"
    recovery: "Default to 'voting' algorithm"

performance:
  - metric: "execution_time"
    threshold: "1000ms"
    description: "Consensus calculation should complete within 1 second for typical inputs"

security:
  - aspect: "input_validation"
    description: "Validate all input parameters before processing"
  - aspect: "output_sanitization"
    description: "Ensure output doesn't contain sensitive information"