mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
* feat(adr): Add ADR-027 Native TeammateTool Integration Comprehensive architecture for integrating Claude Flow with Claude Code's native TeammateTool multi-agent orchestration system (v2.1.19+). Key features: - TeammateBridge: Core bridge class with all 13 TeammateTool operations - Team management: spawn, discover, join/leave workflows - Mailbox integration: Inter-agent messaging via ~/.claude/teams/ - Plan approval: Submit, approve/reject, launch swarm workflow - MCP tools: 9 new tools exposing native capabilities - Claude Flow integration: Topology and agent type mapping - Security model: Explicit tool grants, approval quorums - Migration path: Native when available, MCP fallback Based on analysis of Claude Code v2.1.19 binary confirming: - 34 TeammateTool references - 154 Teammate class references - 22 spawnTeam operations - CLAUDE_CODE_TEAM_NAME environment variable - tmux and in_process spawn backends Refs: ADR-018, gist/kieranklaassen/d2b35569be2c7f1412c64861a219d51f * docs: Add architectural comparison between Claude Flow V3 and TeammateTool Detailed side-by-side analysis showing 92% architectural overlap between Claude Flow V3's swarm system and Claude Code's TeammateTool (v2.1.19). Key findings: - Identical concepts: team/swarm, topology, agent types, message bus - Same workflows: join/leave approval, plan consensus, broadcast - Matching structures: agent state, message format, spawn backends - Different terminology: same underlying architecture Comparison includes: - Core architecture mapping - Data structure comparison - Code examples from both systems - Timeline analysis - 30+ side-by-side comparisons Refs: Claude Flow V3 source, Claude Code v2.1.19 binary analysis * docs(adr): Add ADR-027 gap analysis - 15 missing features identified Comprehensive analysis of features missing from the TeammateTool plugin: CRITICAL (Phase 1): - Delegate mode: Authority delegation between teammates - Team context: Shared variables, permissions, environment - Permission updates: Dynamic permission changes mid-execution - Session memory: Persist context across sessions HIGH PRIORITY (Phase 2): - Remote sync: pushToRemote to Claude.ai - Transcript sharing: Share messages between teammates - Error handling: Recovery strategies, error types - Memory bridge: Sync to Claude Flow HNSW MEDIUM (Phase 3): - Teleport: Resume teams across terminal instances - Plan control: Pause/resume/reentry for plans - Hook integration: Claude Flow hook system - Consensus bridge: Native vs advanced algorithms LOW (Phase 4): - tmux backend config: Pane layouts, prefix keys - Worker threads: Parallel execution within teammate - Swarm teammate type: Optimized for parallel tasks Estimated additional code: ~1,550 lines (total: ~2,950) * feat(teammate-plugin): Complete @claude-flow/teammate-plugin implementation Implements all 15 features from ADR-027 gap analysis: Core Features: - TeammateBridge class with version detection (>= 2.1.19) - Team management (spawn, discover, load teams) - Teammate spawning with AgentInput schema - Mailbox messaging (direct and broadcast) - Plan approval workflow (submit, approve, reject, launch) Extended Features: - Delegate mode (delegateToTeammate, revokeDelegation) - Remote sync (pushToRemote, pullFromRemote, syncWithRemote) - Session memory persistence (save/load) - Team context management (shared variables, permissions) - Teleport (resume teams across terminal instances) - Plan control (pause, resume, re-enter plan mode) - Transcript sharing between teammates - Error handling with 18 error codes Package includes: - 16 MCP tools for complete TeammateTool integration - TDD test suite with Vitest - Comprehensive README with version requirements - TypeScript definitions (~500 lines) - ~2000 lines total implementation Requires Claude Code >= 2.1.19 for native TeammateTool support. * security+perf(teammate-plugin): Add comprehensive security hardening and optimizations Security Improvements: - Add input validation for team/teammate names (path traversal prevention) - Implement SAFE_NAME_PATTERN regex for alphanumeric+dash+underscore only - Add RESERVED_NAMES blocklist to prevent .., config, state exploitation - Implement validatePath() to ensure paths stay within teams directory - Add safeJSONParse() with size limits (1MB max) to prevent DoS - Sanitize environment variables to remove control characters - Set restrictive file permissions (0o600 for files, 0o700 for dirs) - Add MAX_PARAM_LENGTH and MAX_ARRAY_ITEMS validation in MCP tools - Export SECURITY_LIMITS constants for configurability Performance Optimizations: - Add debounced file writes (500ms) to reduce I/O operations - Implement team config caching with 30s TTL - Add flushPendingWrites() for graceful cleanup - Add invalidateConfigCache() on team changes Security Constants: - MAX_NAME_LENGTH: 64 characters - MAX_PAYLOAD_SIZE: 1MB - MAX_TEAMMATES_PER_TEAM: 50 - MAX_MESSAGES_PER_MAILBOX: 1000 - MAX_DELEGATION_DEPTH: 5 Addresses OWASP: - A01:2021 Path Traversal - A03:2021 Injection - A05:2021 Security Misconfiguration * feat(teammate-plugin): Add rate limiting, metrics, health checks, and circuit breaker Production-ready features for enterprise deployment: Rate Limiting: - Configurable limits for spawn, messages, broadcasts, plans - Per-minute sliding window with automatic reset - Remaining quota tracking and rate limit state access - Default: 10 spawns, 100 messages, 20 broadcasts per minute Metrics & Telemetry: - Counter metrics: teams, teammates, messages, errors, etc. - Gauge metrics: active teams, active teammates, pending plans - Histogram metrics: spawn latency, message latency, approval latency - Percentile calculations (p50, p95, p99) - MetricSnapshot for point-in-time observability Health Checks: - Per-teammate health monitoring with configurable intervals - Health states: healthy, degraded, unhealthy, unknown - Consecutive failure/success thresholds - Team-level health reports with overall status - Auto-emit events on status changes Circuit Breaker Pattern: - States: closed, open, half-open - Configurable failure/success thresholds - Timeout protection on external calls - Automatic reset after cooldown period Retry Logic: - Exponential backoff with configurable multiplier - Max delay cap to prevent infinite waits - Retryable error codes for selective retry - withRetry() helper function New Configuration Constants: - RATE_LIMIT_DEFAULTS - HEALTH_CHECK_DEFAULTS - RETRY_DEFAULTS - DEFAULT_CIRCUIT_BREAKER_CONFIG Public API Additions: - getMetrics(), getLatencyPercentile(), resetMetrics() - getTeammateHealth(), getTeamHealth() - getRateLimitRemaining(), isRateLimited(), resetRateLimits() - getCircuitBreakerState(), resetCircuitBreaker() Integrated into operations: - spawnTeammate: rate limiting + latency tracking + health checks - sendMessage: rate limiting + latency tracking - broadcast: rate limiting + metrics * feat(teammate-plugin): Add BMSSP-powered optimization (10-15x faster) - Add @ruvnet/bmssp dependency for WebAssembly graph optimization - Create TopologyOptimizer with WasmGraph integration for shortest path computation, topology statistics, and optimization suggestions - Create SemanticRouter with WasmNeuralBMSSP for intelligent task-to- teammate matching using skill embeddings and neural pathfinding - Integrate optimizers into TeammateBridge with enableOptimizers(), findOptimalPath(), getTopologyStats(), findBestTeammateForTask() - Add 5 new MCP tools for optimization (21 total): - teammate_enable_optimizers - teammate_find_optimal_path - teammate_get_topology_stats - teammate_route_task - teammate_batch_route - JavaScript fallback when WASM unavailable - Performance learning via updateTeammatePerformance() * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:09:07Z - Changes: 6 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:09:17Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:10:35Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:10:36Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:10:37Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:10:38Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:10:39Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:10:40Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:11:39Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:11:47Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:12:00Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:13:27Z - Changes: 33 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:13:50Z - Changes: 2 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:14:34Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:17:14Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:17:41Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:17:55Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:18:40Z - Changes: 2 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:19:21Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:19:52Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:20:03Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:20:10Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:20:16Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:22:03Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:22:10Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:22:16Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:29:59Z - Changes: 6 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:30:47Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:31:00Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Checkpoint: File edits Automatic checkpoint created by Claude Code - Branch: claude/review-claude-flow-integration-A0c3R - Timestamp: 2026-01-25T15:32:20Z - Changes: 2 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Update README.md: Revise badge section and enhance documentation structure * fix: Use main branch README.md to resolve conflicts Co-Authored-By: claude-flow <ruv@ruv.net> --------- Co-authored-by: Claude <noreply@anthropic.com>
714 lines
17 KiB
Markdown
714 lines
17 KiB
Markdown
# @claude-flow/teammate-plugin
|
|
|
|
Native **TeammateTool** integration plugin for Claude Flow. Bridges Claude Code v2.1.19+ multi-agent orchestration capabilities with Claude Flow's swarm system.
|
|
|
|
[](https://badge.fury.io/js/%40claude-flow%2Fteammate-plugin)
|
|
[](https://opensource.org/licenses/MIT)
|
|
|
|
## Requirements
|
|
|
|
| Requirement | Minimum Version | Recommended |
|
|
|-------------|-----------------|-------------|
|
|
| **Claude Code** | **>= 2.1.19** | Latest |
|
|
| Node.js | >= 18.0.0 | >= 20.0.0 |
|
|
| npm | >= 9.0.0 | >= 10.0.0 |
|
|
|
|
> **IMPORTANT:** This plugin requires Claude Code version **2.1.19 or higher**. The TeammateTool functionality was introduced in this version and is not available in earlier releases.
|
|
|
|
### Version Check
|
|
|
|
```bash
|
|
# Check your Claude Code version
|
|
claude --version
|
|
|
|
# Should output: 2.1.19 or higher
|
|
```
|
|
|
|
If your version is below 2.1.19, update Claude Code:
|
|
|
|
```bash
|
|
claude update
|
|
```
|
|
|
|
## Installation
|
|
|
|
### Via Claude Code CLI (Recommended)
|
|
|
|
Install directly using Claude Code's plugin system:
|
|
|
|
```bash
|
|
# Install from npm registry
|
|
claude plugins install @claude-flow/teammate-plugin
|
|
|
|
# Or install from Claude Flow plugin registry (IPFS-backed)
|
|
claude plugins install teammate-plugin --registry claude-flow
|
|
```
|
|
|
|
### Via npm
|
|
|
|
```bash
|
|
npm install @claude-flow/teammate-plugin
|
|
```
|
|
|
|
Or with pnpm:
|
|
|
|
```bash
|
|
pnpm add @claude-flow/teammate-plugin
|
|
```
|
|
|
|
### Via Claude Flow CLI
|
|
|
|
```bash
|
|
# Install via claude-flow plugin manager
|
|
npx @claude-flow/cli@latest plugins install --name @claude-flow/teammate-plugin
|
|
|
|
# Or add to your claude-flow.config.json
|
|
npx @claude-flow/cli@latest config set plugins.teammate-plugin.enabled true
|
|
```
|
|
|
|
### Verify Installation
|
|
|
|
```bash
|
|
# Check plugin is loaded
|
|
claude plugins list
|
|
|
|
# Or via claude-flow
|
|
npx @claude-flow/cli@latest plugins list
|
|
```
|
|
|
|
## Quick Start
|
|
|
|
```typescript
|
|
import { createTeammateBridge } from '@claude-flow/teammate-plugin';
|
|
|
|
// Initialize the bridge
|
|
const bridge = await createTeammateBridge();
|
|
|
|
// Check compatibility
|
|
const version = bridge.getVersionInfo();
|
|
console.log(`Claude Code: ${version.claudeCode}`);
|
|
console.log(`Compatible: ${version.compatible}`);
|
|
|
|
if (!version.compatible) {
|
|
console.error('Please upgrade Claude Code to >= 2.1.19');
|
|
process.exit(1);
|
|
}
|
|
|
|
// Create a team
|
|
const team = await bridge.spawnTeam({
|
|
name: 'my-dev-team',
|
|
topology: 'hierarchical',
|
|
maxTeammates: 6,
|
|
planModeRequired: true,
|
|
});
|
|
|
|
// Spawn teammates (returns AgentInput for Claude Code Task tool)
|
|
const coder = await bridge.spawnTeammate({
|
|
name: 'coder-1',
|
|
role: 'coder',
|
|
prompt: 'Implement the authentication feature using JWT',
|
|
teamName: 'my-dev-team',
|
|
model: 'sonnet',
|
|
allowedTools: ['Edit', 'Write', 'Read', 'Bash'],
|
|
});
|
|
|
|
// The agentInput can be passed to Claude Code's Task tool
|
|
const agentInput = bridge.buildAgentInput({
|
|
name: 'tester-1',
|
|
role: 'tester',
|
|
prompt: 'Write tests for the authentication feature',
|
|
teamName: 'my-dev-team',
|
|
model: 'haiku',
|
|
});
|
|
|
|
console.log('Pass this to Task tool:', agentInput);
|
|
```
|
|
|
|
## Features
|
|
|
|
### Core Features (from TeammateTool)
|
|
|
|
| Feature | Description | TeammateTool Operation |
|
|
|---------|-------------|------------------------|
|
|
| Team Management | Create, discover, load teams | `spawnTeam`, `discoverTeams` |
|
|
| Teammate Spawning | Spawn agents with native support | `AgentInput` schema |
|
|
| Join/Leave Workflow | Request-approve-reject pattern | `requestJoin`, `approveJoin`, `rejectJoin` |
|
|
| Messaging | Direct and broadcast messages | `write`, `broadcast` |
|
|
| Plan Approval | Submit, vote, execute plans | `approvePlan`, `rejectPlan` |
|
|
| Swarm Launch | Launch multi-agent execution | `launchSwarm`, `teammateCount` |
|
|
| Shutdown | Graceful teammate termination | `requestShutdown`, `approveShutdown` |
|
|
|
|
### Extended Features (Plugin Additions)
|
|
|
|
| Feature | Description |
|
|
|---------|-------------|
|
|
| Delegation | Delegate authority between teammates |
|
|
| Team Context | Shared variables, permissions, environment |
|
|
| Permission Updates | Dynamic permission changes mid-execution |
|
|
| Session Memory | Persist teammate context across sessions |
|
|
| Remote Sync | Push team to Claude.ai (experimental) |
|
|
| Transcript Sharing | Share message history between teammates |
|
|
| Teleport | Resume teams across terminal instances |
|
|
| Plan Control | Pause, resume, modify plans mid-execution |
|
|
|
|
## API Reference
|
|
|
|
### TeammateBridge
|
|
|
|
The main class for interacting with TeammateTool.
|
|
|
|
#### Initialization
|
|
|
|
```typescript
|
|
import { createTeammateBridge, TeammateBridge } from '@claude-flow/teammate-plugin';
|
|
|
|
// Factory function (recommended)
|
|
const bridge = await createTeammateBridge({
|
|
fallbackToMCP: true, // Fallback to MCP if TeammateTool unavailable
|
|
memory: {
|
|
autoPersist: true,
|
|
persistIntervalMs: 60000,
|
|
},
|
|
});
|
|
|
|
// Or direct instantiation
|
|
const bridge = new TeammateBridge(config);
|
|
await bridge.initialize();
|
|
```
|
|
|
|
#### Team Management
|
|
|
|
```typescript
|
|
// Create team
|
|
const team = await bridge.spawnTeam({
|
|
name: 'my-team',
|
|
topology: 'hierarchical', // 'flat' | 'hierarchical' | 'mesh'
|
|
maxTeammates: 8,
|
|
planModeRequired: true,
|
|
autoApproveJoin: true,
|
|
delegationEnabled: true,
|
|
});
|
|
|
|
// Discover existing teams
|
|
const teams = await bridge.discoverTeams();
|
|
// ['team-1', 'team-2', ...]
|
|
|
|
// Load existing team
|
|
const existingTeam = await bridge.loadTeam('team-1');
|
|
|
|
// Get team state
|
|
const state = bridge.getTeamState('my-team');
|
|
```
|
|
|
|
#### Teammate Spawning
|
|
|
|
```typescript
|
|
// Spawn teammate
|
|
const teammate = await bridge.spawnTeammate({
|
|
name: 'coder-1',
|
|
role: 'coder',
|
|
prompt: 'Implement feature X',
|
|
teamName: 'my-team',
|
|
model: 'sonnet', // 'sonnet' | 'opus' | 'haiku'
|
|
allowedTools: ['Edit', 'Write', 'Read'],
|
|
mode: 'default', // 'default' | 'plan' | 'delegate' | etc.
|
|
});
|
|
|
|
// Build AgentInput for Task tool
|
|
const agentInput = bridge.buildAgentInput({
|
|
name: 'reviewer-1',
|
|
role: 'reviewer',
|
|
prompt: 'Review code changes',
|
|
teamName: 'my-team',
|
|
});
|
|
// Pass agentInput to Claude Code's Task tool
|
|
```
|
|
|
|
#### Messaging
|
|
|
|
```typescript
|
|
// Send direct message
|
|
const message = await bridge.sendMessage(
|
|
'my-team',
|
|
'sender-id',
|
|
'recipient-id',
|
|
{
|
|
type: 'task',
|
|
payload: { action: 'implement', target: 'auth' },
|
|
priority: 'high',
|
|
}
|
|
);
|
|
|
|
// Broadcast to all teammates
|
|
await bridge.broadcast('my-team', 'coordinator-id', {
|
|
type: 'status',
|
|
payload: { phase: 'implementation' },
|
|
});
|
|
|
|
// Read mailbox
|
|
const messages = await bridge.readMailbox('my-team', 'teammate-id');
|
|
```
|
|
|
|
#### Plan Approval
|
|
|
|
```typescript
|
|
// Submit plan
|
|
const plan = await bridge.submitPlan('my-team', {
|
|
description: 'Implement authentication feature',
|
|
proposedBy: 'coordinator-id',
|
|
steps: [
|
|
{ order: 1, action: 'Create user model', tools: ['Edit'], assignee: 'coder-1' },
|
|
{ order: 2, action: 'Add JWT middleware', tools: ['Edit'], assignee: 'coder-1' },
|
|
{ order: 3, action: 'Write unit tests', tools: ['Edit'], assignee: 'tester-1' },
|
|
],
|
|
requiredApprovals: 2,
|
|
});
|
|
|
|
// Approve plan
|
|
await bridge.approvePlan('my-team', plan.id, 'reviewer-id');
|
|
|
|
// Launch swarm (after approval)
|
|
const exitPlanInput = await bridge.launchSwarm('my-team', plan.id, 3);
|
|
// Pass exitPlanInput to ExitPlanMode tool
|
|
```
|
|
|
|
#### Delegation
|
|
|
|
```typescript
|
|
// Delegate authority
|
|
const delegation = await bridge.delegateToTeammate(
|
|
'my-team',
|
|
'lead-id',
|
|
'dev-id',
|
|
['approve_plan', 'spawn_teammate']
|
|
);
|
|
|
|
// Revoke delegation
|
|
await bridge.revokeDelegation('my-team', 'lead-id', 'dev-id');
|
|
```
|
|
|
|
#### Team Context
|
|
|
|
```typescript
|
|
// Update context
|
|
await bridge.updateTeamContext('my-team', {
|
|
sharedVariables: {
|
|
apiEndpoint: 'https://api.example.com',
|
|
version: '1.0.0',
|
|
},
|
|
inheritedPermissions: ['read', 'write'],
|
|
environmentVariables: {
|
|
NODE_ENV: 'development',
|
|
},
|
|
});
|
|
|
|
// Get context
|
|
const context = bridge.getTeamContext('my-team');
|
|
```
|
|
|
|
#### Session Memory
|
|
|
|
```typescript
|
|
// Save teammate memory
|
|
await bridge.saveTeammateMemory('my-team', 'teammate-id');
|
|
|
|
// Load teammate memory
|
|
const memory = await bridge.loadTeammateMemory('my-team', 'teammate-id');
|
|
|
|
// Share transcript
|
|
await bridge.shareTranscript('my-team', 'from-id', 'to-id', {
|
|
start: 0,
|
|
end: 10,
|
|
});
|
|
```
|
|
|
|
#### Teleport
|
|
|
|
```typescript
|
|
// Check if teleport is possible
|
|
const { canTeleport, blockers } = await bridge.canTeleport('my-team', {
|
|
workingDirectory: '/path/to/new/dir',
|
|
gitBranch: 'feature/auth',
|
|
});
|
|
|
|
// Teleport team
|
|
if (canTeleport) {
|
|
const result = await bridge.teleportTeam('my-team', {
|
|
workingDirectory: '/path/to/new/dir',
|
|
gitBranch: 'feature/auth',
|
|
});
|
|
}
|
|
```
|
|
|
|
### MCP Tools
|
|
|
|
The plugin provides 16 MCP tools for use with Claude Code's MCP server:
|
|
|
|
```typescript
|
|
import { TEAMMATE_MCP_TOOLS, handleMCPTool } from '@claude-flow/teammate-plugin';
|
|
|
|
// List all tools
|
|
console.log(TEAMMATE_MCP_TOOLS.map(t => t.name));
|
|
// [
|
|
// 'teammate_spawn_team',
|
|
// 'teammate_discover_teams',
|
|
// 'teammate_spawn',
|
|
// 'teammate_send_message',
|
|
// 'teammate_broadcast',
|
|
// 'teammate_submit_plan',
|
|
// 'teammate_approve_plan',
|
|
// 'teammate_launch_swarm',
|
|
// 'teammate_delegate',
|
|
// 'teammate_update_context',
|
|
// 'teammate_save_memory',
|
|
// 'teammate_share_transcript',
|
|
// 'teammate_push_remote',
|
|
// 'teammate_teleport',
|
|
// 'teammate_get_status',
|
|
// 'teammate_cleanup',
|
|
// ]
|
|
|
|
// Handle tool call
|
|
const result = await handleMCPTool(bridge, 'teammate_spawn_team', {
|
|
name: 'my-team',
|
|
topology: 'hierarchical',
|
|
});
|
|
```
|
|
|
|
## Events
|
|
|
|
The bridge emits events for all operations:
|
|
|
|
```typescript
|
|
bridge.on('team:spawned', ({ team, config }) => {
|
|
console.log(`Team ${team} created`);
|
|
});
|
|
|
|
bridge.on('teammate:spawned', ({ teammate, agentInput }) => {
|
|
console.log(`Teammate ${teammate.name} spawned`);
|
|
});
|
|
|
|
bridge.on('plan:approved', ({ team, plan }) => {
|
|
console.log(`Plan ${plan.id} approved`);
|
|
});
|
|
|
|
bridge.on('delegate:granted', ({ team, from, to, permissions }) => {
|
|
console.log(`${from} delegated to ${to}: ${permissions.join(', ')}`);
|
|
});
|
|
|
|
bridge.on('teleport:completed', ({ team, result }) => {
|
|
console.log(`Team ${team} teleported successfully`);
|
|
});
|
|
```
|
|
|
|
## Error Handling
|
|
|
|
```typescript
|
|
import { TeammateError, TeammateErrorCode } from '@claude-flow/teammate-plugin';
|
|
|
|
try {
|
|
await bridge.launchSwarm('my-team', 'plan-id');
|
|
} catch (error) {
|
|
if (error instanceof TeammateError) {
|
|
switch (error.code) {
|
|
case TeammateErrorCode.PLAN_NOT_APPROVED:
|
|
console.log('Plan needs approval first');
|
|
break;
|
|
case TeammateErrorCode.TEAM_NOT_FOUND:
|
|
console.log(`Team not found: ${error.teamName}`);
|
|
break;
|
|
case TeammateErrorCode.VERSION_INCOMPATIBLE:
|
|
console.log('Claude Code version too old');
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Configuration
|
|
|
|
```typescript
|
|
import { createTeammateBridge, DEFAULT_PLUGIN_CONFIG } from '@claude-flow/teammate-plugin';
|
|
|
|
const bridge = await createTeammateBridge({
|
|
autoInitialize: true,
|
|
fallbackToMCP: true,
|
|
|
|
recovery: {
|
|
maxRetries: 3,
|
|
retryDelayMs: 1000,
|
|
exponentialBackoff: true,
|
|
fallbackToMCP: true,
|
|
autoCleanupOnError: true,
|
|
},
|
|
|
|
delegation: {
|
|
maxDepth: 3,
|
|
autoExpireMs: 3600000, // 1 hour
|
|
requireApproval: false,
|
|
},
|
|
|
|
remoteSync: {
|
|
enabled: false,
|
|
autoSync: false,
|
|
syncInterval: 30000,
|
|
preserveOnDisconnect: true,
|
|
},
|
|
|
|
teleport: {
|
|
autoResume: true,
|
|
gitAware: true,
|
|
preserveMailbox: true,
|
|
preserveMemory: true,
|
|
},
|
|
|
|
memory: {
|
|
autoPersist: true,
|
|
persistIntervalMs: 60000,
|
|
maxSizeMb: 100,
|
|
},
|
|
|
|
mailbox: {
|
|
pollingIntervalMs: 1000,
|
|
maxMessages: 1000,
|
|
retentionMs: 3600000,
|
|
},
|
|
});
|
|
```
|
|
|
|
## Integration with Claude Flow
|
|
|
|
```typescript
|
|
import { createTeammateBridge } from '@claude-flow/teammate-plugin';
|
|
import { UnifiedSwarmCoordinator } from '@claude-flow/swarm';
|
|
|
|
// Create bridge
|
|
const bridge = await createTeammateBridge();
|
|
|
|
// Map Claude Flow topology to team config
|
|
const teamConfig = {
|
|
name: 'cf-team',
|
|
topology: 'hierarchical', // Maps to Claude Flow's hierarchical
|
|
maxTeammates: 8,
|
|
planModeRequired: true,
|
|
};
|
|
|
|
// Create team
|
|
const team = await bridge.spawnTeam(teamConfig);
|
|
|
|
// Map Claude Flow agent types to teammate configs
|
|
const agentMapping = {
|
|
'coder': { role: 'coder', tools: ['Edit', 'Write', 'Read', 'Bash'] },
|
|
'tester': { role: 'tester', tools: ['Read', 'Bash', 'Glob'] },
|
|
'reviewer': { role: 'reviewer', tools: ['Read', 'Grep', 'Glob'] },
|
|
'architect': { role: 'architect', tools: ['Read', 'Glob', 'Grep'] },
|
|
};
|
|
|
|
// Spawn teammates with Claude Flow agent types
|
|
for (const [type, config] of Object.entries(agentMapping)) {
|
|
await bridge.spawnTeammate({
|
|
name: `${type}-1`,
|
|
role: config.role,
|
|
prompt: `You are a ${type}...`,
|
|
teamName: 'cf-team',
|
|
allowedTools: config.tools,
|
|
});
|
|
}
|
|
```
|
|
|
|
## File Structure
|
|
|
|
Teams are stored in `~/.claude/teams/`:
|
|
|
|
```
|
|
~/.claude/teams/
|
|
├── my-team/
|
|
│ ├── config.json # Team configuration
|
|
│ ├── state.json # Team state (teammates, plans)
|
|
│ ├── remote.json # Remote session info (if synced)
|
|
│ ├── mailbox/
|
|
│ │ ├── teammate-1.json
|
|
│ │ └── teammate-2.json
|
|
│ └── memory/
|
|
│ ├── teammate-1.json
|
|
│ └── teammate-2.json
|
|
└── other-team/
|
|
└── ...
|
|
```
|
|
|
|
## Environment Variables
|
|
|
|
The plugin uses these Claude Code environment variables:
|
|
|
|
```bash
|
|
CLAUDE_CODE_TEAM_NAME # Current team context
|
|
CLAUDE_CODE_PLAN_MODE_REQUIRED # Require plan approval
|
|
CLAUDE_CODE_TMUX_SESSION # tmux session name
|
|
CLAUDE_CODE_TMUX_PREFIX # tmux prefix key
|
|
CLAUDE_CODE_TEAMMATE_COMMAND # Custom spawn command
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
### Plugin reports TeammateTool not available
|
|
|
|
```typescript
|
|
const version = bridge.getVersionInfo();
|
|
if (!version.compatible) {
|
|
console.log(`Claude Code version: ${version.claudeCode}`);
|
|
console.log(`Required: >= 2.1.19`);
|
|
console.log('Run: claude update');
|
|
}
|
|
```
|
|
|
|
### Mailbox messages not received
|
|
|
|
Check that mailbox polling is running:
|
|
|
|
```typescript
|
|
// Mailbox is polled automatically, but you can read manually
|
|
const messages = await bridge.readMailbox('my-team', 'teammate-id');
|
|
```
|
|
|
|
### Plan approval stuck
|
|
|
|
Ensure enough teammates have voted:
|
|
|
|
```typescript
|
|
const team = bridge.getTeamState('my-team');
|
|
const plan = team.activePlans.find(p => p.id === planId);
|
|
|
|
console.log(`Approvals: ${plan.approvals.length}/${plan.requiredApprovals}`);
|
|
console.log(`Rejections: ${plan.rejections.length}`);
|
|
```
|
|
|
|
## Testing the Plugin
|
|
|
|
### Run Unit Tests
|
|
|
|
```bash
|
|
cd v3/plugins/teammate-plugin
|
|
|
|
# Install dependencies
|
|
npm install
|
|
|
|
# Run tests
|
|
npm test
|
|
|
|
# Run tests with coverage
|
|
npm run test:coverage
|
|
```
|
|
|
|
### Verify Plugin Functionality
|
|
|
|
```typescript
|
|
import { createTeammateBridge, TEAMMATE_MCP_TOOLS } from '@claude-flow/teammate-plugin';
|
|
|
|
async function verifyPlugin() {
|
|
console.log('=== Plugin Verification ===\n');
|
|
|
|
// 1. Check MCP tools are exported
|
|
console.log(`✓ MCP Tools available: ${TEAMMATE_MCP_TOOLS.length}`);
|
|
|
|
// 2. Initialize bridge
|
|
const bridge = await createTeammateBridge();
|
|
console.log('✓ Bridge initialized');
|
|
|
|
// 3. Check version compatibility
|
|
const version = bridge.getVersionInfo();
|
|
console.log(`✓ Claude Code version: ${version.claudeCode || 'not detected'}`);
|
|
console.log(`✓ Plugin version: ${version.plugin}`);
|
|
console.log(`✓ Compatible: ${version.compatible}`);
|
|
|
|
// 4. Test team creation (if compatible)
|
|
if (version.compatible) {
|
|
const team = await bridge.spawnTeam({ name: 'test-team' });
|
|
console.log(`✓ Team created: ${team.name}`);
|
|
|
|
// Cleanup
|
|
await bridge.cleanup('test-team');
|
|
console.log('✓ Cleanup successful');
|
|
}
|
|
|
|
console.log('\n=== All checks passed! ===');
|
|
}
|
|
|
|
verifyPlugin().catch(console.error);
|
|
```
|
|
|
|
### Verify via CLI
|
|
|
|
```bash
|
|
# Check plugin is registered
|
|
npx @claude-flow/cli@latest plugins list | grep teammate
|
|
|
|
# Check plugin info
|
|
npx @claude-flow/cli@latest plugins info teammate-plugin
|
|
|
|
# Test MCP tools
|
|
npx @claude-flow/cli@latest mcp tools | grep teammate
|
|
```
|
|
|
|
## Plugin Registry (IPFS)
|
|
|
|
This plugin is published to the Claude Flow Plugin Registry on IPFS for decentralized distribution.
|
|
|
|
### Registry Entry
|
|
|
|
```json
|
|
{
|
|
"name": "teammate-plugin",
|
|
"package": "@claude-flow/teammate-plugin",
|
|
"version": "1.0.0-alpha.1",
|
|
"description": "Native TeammateTool integration for Claude Code v2.1.19+",
|
|
"author": "Claude Flow Team",
|
|
"license": "MIT",
|
|
"repository": "https://github.com/ruvnet/claude-flow",
|
|
"keywords": ["claude-code", "teammate", "multi-agent", "swarm"],
|
|
"requirements": {
|
|
"claudeCode": ">=2.1.19",
|
|
"node": ">=18.0.0"
|
|
},
|
|
"mcpTools": 21,
|
|
"features": [
|
|
"team-management",
|
|
"teammate-spawning",
|
|
"messaging",
|
|
"plan-approval",
|
|
"delegation",
|
|
"remote-sync",
|
|
"bmssp-optimization"
|
|
]
|
|
}
|
|
```
|
|
|
|
### Install from Registry
|
|
|
|
```bash
|
|
# Install from IPFS-backed registry
|
|
npx @claude-flow/cli@latest plugins install teammate-plugin --registry ipfs
|
|
|
|
# Or specify registry CID directly
|
|
npx @claude-flow/cli@latest plugins install teammate-plugin --cid <registry-cid>
|
|
```
|
|
|
|
### Verify Registry Integrity
|
|
|
|
```bash
|
|
# Check plugin hash matches registry
|
|
npx @claude-flow/cli@latest plugins verify teammate-plugin
|
|
|
|
# View registry metadata
|
|
npx @claude-flow/cli@latest plugins registry info
|
|
```
|
|
|
|
## License
|
|
|
|
MIT
|
|
|
|
## Related
|
|
|
|
- [Claude Flow](https://github.com/ruvnet/claude-flow) - Multi-agent orchestration framework
|
|
- [Claude Code](https://github.com/anthropics/claude-code) - Anthropic's CLI for Claude
|
|
- [ADR-027](../implementation/adrs/ADR-027-teammate-tool-integration.md) - Architecture decision record
|