Cfn event bus

From masharratt/claude-flow-novice · View interactive version

Cfn event bus is an AI agent skill from the GitHub repository masharratt/claude-flow-novice. Event Bus provides a centralized event-driven communication system for agent coordination, system events, and lifecycle tracking. Built on the QEEventBus architecture, it enables decoupled, asynchrono

How to use this skill

Skill file

Event Bus Skill

Version

Version: 1.0.0

Status: OPERATIONAL

Overview

Event Bus provides a centralized event-driven communication system for agent coordination, system events, and lifecycle tracking. Built on the QEEventBus architecture, it enables decoupled, asynchronous messaging between agents and system components.

Features

Core Components

1. Event Router and Dispatcher

The Event Bus uses a pub/sub architecture with the following key components:

Event Emitter: Core EventBus class from .claude/core/cfn-event-bus.js

Event Statistics:

2. Agent Lifecycle Events

Track agent state transitions across the execution lifecycle:

Lifecycle Stages:

Lifecycle Metadata:

{
  "agentId": "backend-dev-1",
  "taskId": "auth-system",
  "timestamp": 1729311234,
  "metadata": {
    "reason": "Task completed successfully",
    "confidence": 0.92,
    "duration": 45000
  }
}

3. System Events

Pre-defined system-wide events for cross-agent coordination:

Common System Events:

4. WASM JSON Integration

Status: Placeholder for future implementation

Future integration with WASM-based JSON processing for:

Agent Integration Examples

1. Publishing Events

Basic Event Publishing
# Publish task completion event
./.claude/skills/event-bus/invoke-event-publish.sh \
  --topic "task:completed" \
  --payload '{
    "taskId": "auth-system",
    "agentId": "backend-dev-1",
    "confidence": 0.92,
    "timestamp": '$(date +%s)'
  }'
Publishing with Trace ID
# Publish with distributed tracing
./.claude/skills/event-bus/invoke-event-publish.sh \
  --topic "validation:passed" \
  --payload '{
    "taskId": "deploy-feature",
    "validator": "security-agent",
    "checks": ["input-validation", "auth-check", "rate-limiting"]
  }' \
  --trace-id "trace-123-abc"

2. Subscribing to Events

Subscribe to Single Event
# Subscribe to agent completion events
./.claude/skills/event-bus/invoke-event-subscribe.sh \
  --topic "agent:completed" \
  --callback "handle_agent_complete"

# Callback function definition
handle_agent_complete() {
  local event_data="$1"
  echo "Agent completed: $(echo "$event_data" | jq -r '.agentId')"
  # Process event...
}
Filtered Event Subscription
# Subscribe only to high-confidence completions
./.claude/skills/event-bus/invoke-event-subscribe.sh \
  --topic "agent:completed" \
  --filter 'select(.confidence >= 0.90)' \
  --callback "handle_high_confidence_completion"

3. Agent Lifecycle Tracking

Track Agent Spawn
# Record agent creation
./.claude/skills/event-bus/invoke-lifecycle-track.sh \
  --agent-id "backend-dev-1" \
  --event "spawn" \
  --metadata '{
    "taskId": "auth-system",
    "role": "backend-developer",
    "timestamp": '$(date +%s)'
  }'
Track Agent Completion
# Record successful completion
./.claude/skills/event-bus/invoke-lifecycle-track.sh \
  --agent-id "backend-dev-1" \
  --event "complete" \
  --metadata '{
    "taskId": "auth-system",
    "confidence": 0.92,
    "duration": 45000,
    "filesModified": 12
  }'
Track Agent Failure
# Record agent failure
./.claude/skills/event-bus/invoke-lifecycle-track.sh \
  --agent-id "backend-dev-1" \
  --event "fail" \
  --metadata '{
    "taskId": "auth-system",
    "error": "TypeScript compilation failed",
    "stage": "post-edit-validation",
    "timestamp": '$(date +%s)'
  }'
Track Agent Timeout
# Record timeout
./.claude/skills/event-bus/invoke-lifecycle-track.sh \
  --agent-id "backend-dev-1" \
  --event "timeout" \
  --metadata '{
    "taskId": "auth-system",
    "timeLimit": 300000,
    "elapsed": 305000
  }'

Integration Patterns

Pattern 1: Event-Driven Coordination

Use events to coordinate agent workflows without tight coupling:

# Agent A publishes completion
./.claude/skills/event-bus/invoke-event-publish.sh \
  --topic "code:ready" \
  --payload '{"taskId": "auth", "status": "ready-for-review"}'

# Agent B subscribes and auto-triggers
./.claude/skills/event-bus/invoke-event-subscribe.sh \
  --topic "code:ready" \
  --callback "start_review_process"

Pattern 2: Lifecycle Monitoring

Track agent progress across CFN Loop iterations:

# Iteration 1 start
./.claude/skills/event-bus/invoke-lifecycle-track.sh \
  --agent-id "coder-1" \
  --event "spawn" \
  --metadata '{"iteration": 1, "taskId": "auth"}'

# Iteration 1 complete
./.claude/skills/event-bus/invoke-lifecycle-track.sh \
  --agent-id "coder-1" \
  --event "complete" \
  --metadata '{"iteration": 1, "confidence": 0.75}'

# Iteration 2 start (after feedback)
./.claude/skills/event-bus/invoke-lifecycle-track.sh \
  --agent-id "coder-1" \
  --event "spawn" \
  --metadata '{"iteration": 2, "taskId": "auth"}'

Pattern 3: Consensus Broadcasting

Broadcast consensus events to all waiting agents:

# Coordinator publishes consensus
./.claude/skills/event-bus/invoke-event-publish.sh \
  --topic "consensus:reached" \
  --payload '{
    "taskId": "auth-system",
    "avgConfidence": 0.93,
    "iteration": 3,
    "agents": ["coder-1", "reviewer-1", "tester-1"]
  }'

# All agents subscribe and receive notification
./.claude/skills/event-bus/invoke-event-subscribe.sh \
  --topic "consensus:reached" \
  --callback "handle_consensus"

Event Schema Guidelines

Standard Event Format

All events should follow this structure:

{
  "eventType": "agent:completed",
  "timestamp": 1729311234,
  "source": {
    "agentId": "backend-dev-1",
    "taskId": "auth-system"
  },
  "payload": {
    "confidence": 0.92,
    "metrics": {
      "duration": 45000,
      "filesModified": 12
    }
  },
  "traceId": "trace-123-abc"
}

Lifecycle Event Format

{
  "eventType": "lifecycle",
  "stage": "complete",
  "agentId": "backend-dev-1",
  "taskId": "auth-system",
  "timestamp": 1729311234,
  "metadata": {
    "confidence": 0.92,
    "duration": 45000
  }
}

Available Invoke Scripts

1. invoke-event-publish.sh

Publish events to the event bus.

Arguments:

Returns: JSON with publish status and event ID

2. invoke-event-subscribe.sh

Subscribe to event topics.

Arguments:

Returns: Subscription ID

3. invoke-lifecycle-track.sh

Track agent lifecycle events.

Arguments:

Returns: JSON with tracking confirmation

4. test-event-bus.sh

Comprehensive test suite for Event Bus functionality.

Tests:

Event Bus vs Redis Coordination

Use Event Bus When:

Use Redis Coordination When:

Combined Usage:

Use both for comprehensive coordination:

# Redis: Block until agent ready
./.claude/skills/redis-coordination/invoke-waiting-mode.sh enter \
  --task-id "auth" --agent-id "coder-1" --context "waiting"

# Event Bus: Notify all watchers
./.claude/skills/event-bus/invoke-event-publish.sh \
  --topic "agent:waiting" \
  --payload '{"agentId": "coder-1", "status": "blocked"}'

Future Enhancements

WASM JSON Processing

Future implementation will include:

Advanced Features (Roadmap)

Configuration

Event Bus behavior can be configured via:

Troubleshooting

High Memory Usage

# Reset event statistics to free memory
node -e "
  const { eventBus } = require('./.claude/core/cfn-event-bus.js');
  eventBus.resetStats();
  console.log('Stats reset');
"

Event Not Received

  1. Verify topic name matches exactly
  2. Check callback function is defined
  3. Enable debug mode: EVENTBUS_DEBUG=true
  4. Check event statistics for publish confirmation

Lifecycle Events Missing

  1. Ensure invoke-lifecycle-track.sh is called
  2. Verify JSON metadata is valid
  3. Check agent-id matches expected format

Related Skills

Support

For issues or questions:

  1. Check test suite: .claude/skills/event-bus/test-event-bus.sh
  2. Review event statistics via getEventStats()
  3. Enable debug logging with EVENTBUS_DEBUG=true
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.