# debatewiki opencode plugin - Main Entry Point for Sisyphus Orchestration

Based on Sisyphus Orchestrator pattern from oh-my-opencode, this plugin provides multi-agent forum debate, wiki collaboration, and knowledge synthesis with grounded theory support.

## Project Overview

sisyphus-debatewiki-plugin is a multi-agent forum debate, wiki collaboration and knowledge synthesis system designed for OpenCode. The project implements mixed TypeScript/JavaScript + Go architecture, following Sisyphus Orchestrator pattern.

### Core Features

1. **Sisyphus Orchestration**: Fully based on Sisyphus pattern, compatible with oh-my-opencode architecture
2. **Agent Driven**: Each function handled by specialized agent
3. **Toolized Operations**: Core functions provided as reusable tools
4. **Event Driven**: Uses Hook mechanism to respond to events
5. **Task Delegation**: Delegates to specialized agents via sisyphus_task
6. **Architecture Compatible**: Fully compatible with oh-my-opencode's Sisyphus pattern
7. **No Constructor Issues**: Avoids class constructor call problems

### Architecture Features

- **Forum Agent**: Coordinates multi-agent debates and discussions
- **Consensus Agent**: Calculates various types of consensus
- **Wiki Agent**: Manages wiki collaboration
- **Grounded Theory Agent**: Performs qualitative research

### Functional Modules

#### 1. Forum Engine
- **Multi-Debate Flows**: Supports free debate, adversarial debate, group discussion, etc.
- **Agent Coordination**: Coordinates multi-agent participation in discussions
- **Phase Management**: Manages different phases of debates
- **Message Aggregation**: Collects and organizes discussion messages
- **Todo Tracking**: Tracks discussion-related todos

#### 2. Consensus Algorithms
- **Voting Consensus**: Simple majority, absolute majority voting algorithms
- **Deliberation Consensus**: Multi-round deliberation to reach consensus
- **Weighted Consensus**: Consensus based on agent weights
- **Consensus Validation**: Validates consensus effectiveness

#### 3. Wiki Collaboration
- **Multi-mode Collaboration**: Supports sync, async and review workflow collaboration
- **Version Control**: Complete version history tracking
- **Conflict Resolution**: Automatic conflict detection and resolution
- **Permission Management**: Flexible permission control

#### 4. Grounded Theory Engine
- **Open Coding**: Concept identification from data
- **Axial Coding**: Establishing concept relationships
- **Selective Coding**: Building core theory
- **Saturation Testing**: Testing theory completeness

## Usage

### As npm package installation
```bash
npm install -g sisyphus-debatewiki
```

### As independent skills
```bash
# JavaScript
node skills/consensus-skill.js calculateVotingConsensus '{"messages": [...], "threshold": 0.7}'

# Python
python skills/consensus-skill.py calculate_voting_consensus '[json_input]'
```

### Via Sisyphus orchestration
```typescript
import { sisyphus_task } from 'oh-my-opencode';

// Delegate task to specialized agent
const debateResult = await sisyphus_task({
  agent: "forum-engine",
  prompt: "Start a debate on topic X with participants Y",
  skills: ["forum-operations", "session-management", "message-aggregation"],
  run_in_background: false
});

// Calculate consensus
const consensusResult = await sisyphus_task({
  agent: "consensus-engine",
  prompt: "Calculate consensus from messages...",
  skills: ["consensus-algorithms"],
  run_in_background: false
});

// Create wiki page
const wikiResult = await sisyphus_task({
  agent: "wiki-engine",
  prompt: "Create wiki page with title and content...",
  skills: ["wiki-operations"],
  run_in_background: false
});

// Perform grounded theory analysis
const theoryResult = await sisyphus_task({
  agent: "grounded-theory-engine",
  prompt: "Perform grounded theory analysis on data...",
  skills: ["grounded-theory-methodology"],
  run_in_background: true
});
```

## Deployment Instructions

### As npm package installation
```bash
npm install -g sisyphus-debatewiki
```

### As independent skill usage
```bash
# JavaScript
node skills/consensus-skill.js calculateVotingConsensus '{"messages": [...], "threshold": 0.7}'

# Python
python skills/consensus-skill.py calculate_voting_consensus '[json_input]'
```

### Via Sisyphus orchestration
```typescript
import { sisyphus_task } from 'oh-my-opencode';

// Delegate task to specialized agent
const result = await sisyphus_task({
  agent: "forum-engine",
  prompt: "Start a debate on topic X with participants Y",
  skills: ["forum-operations", "session-management", "message-aggregation"],
  run_in_background: false
});
```

### Deploying to OpenCode (Compatibility Notes)
⚠️ **Note**: Testing revealed compatibility issues with certain OpenCode versions ("fn3 is not a function" error). This stems from OpenCode's internal plugin loading mechanism and ES module compatibility.

**Compatibility Solutions Implemented**:
1. **API-Compatible Entry Point**: Created entry point that conforms to OpenCode plugin API specifications
2. **Function Call Pattern**: Ensured plugin exports are callable initialization functions
3. **Safe Error Handling**: Implemented safe error handling to prevent OpenCode startup failures

**Deployment Options**:
1. **Standalone Usage (Recommended)**: Install via npm and use skills directly
   ```bash
   npm install -g sisyphus-debatewiki
   node node_modules/sisyphus-debatewiki/skills/consensus-skill.js calculateVotingConsensus '{"messages": [...], "threshold": 0.7}'
   ```

2. **Plugin Integration (Caution)**: If attempting OpenCode plugin integration, backup your configuration first
   ```bash
   # Backup current configuration
   cp ~/.config/opencode/opencode.json ~/.config/opencode/opencode.json.backup

   # Update configuration to include plugin
   # Then verify OpenCode starts properly
   opencode --version
   ```

**Recommended Usage**: Install as independent npm package and use via command line or API calls to skills, which completely avoids compatibility issues.