npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@codmir/cloudflare-workers

v1.0.1

Published

Distributed task execution using Cloudflare Workers as minions

Readme

Cloudflare Workers - Distributed Task Execution

A distributed task execution system using Cloudflare Workers as "minions" for scalable, edge-based processing of coding tasks.

Architecture

Main Agent → Task Divider → Worker Orchestrator → Cloudflare Workers (Minions)
     ↓              ↓              ↓                        ↓
  Complex Task → Micro-Tasks → Load Balancing → Edge Execution
     ↓              ↓              ↓                        ↓
  Integration ← Results Aggregation ← Task Results ← Worker Results

Key Components

1. Task Divider

Breaks down complex tasks into worker-sized chunks:

  • Code Analysis: Parallel file processing, import extraction, syntax validation
  • File Processing: Distributed file analysis and transformation
  • API Integration: Data fetching, transformation, and code generation
  • Content Generation: Parallel section generation with aggregation

2. Worker Orchestrator

Manages distributed Cloudflare Workers:

  • Load Balancing: Round-robin, least-loaded, geographic, capability-based
  • Health Monitoring: Worker heartbeats and performance tracking
  • Task Distribution: Dependency-aware execution planning
  • Retry Logic: Exponential backoff with configurable limits

3. Worker Minions

Lightweight Cloudflare Workers that execute micro-tasks:

  • Capabilities: Text processing, code analysis, API calls, data transformation
  • Edge Execution: Low-latency processing across global regions
  • Stateless Design: Perfect for parallel, independent operations

4. Integration Layer

Connects with existing agent orchestration system:

  • Hybrid Execution: Workers for suitable tasks, agents for complex operations
  • Fallback Strategy: Automatic fallback to agents when workers fail
  • Result Aggregation: Seamless integration of worker and agent results

Usage

Basic Setup

import { createCloudflareIntegration } from '@codmir/cloudflare-workers';

const integration = createCloudflareIntegration({
  accountId: 'your-cloudflare-account-id',
  apiToken: 'your-api-token',
  scriptName: 'codmir-worker-minion',
  maxConcurrentTasks: 100,
  loadBalancing: { type: 'least_loaded' }
});

// Execute a task with worker distribution
const result = await integration.orchestrateWithWorkers(
  "Analyze all TypeScript files in the project",
  {
    projectId: 'proj_123',
    userId: 'user_456',
    files: ['src/app.ts', 'src/utils.ts', 'src/types.ts']
  },
  {
    useWorkers: true,
    workerTaskTypes: ['code_analysis', 'file_processing'],
    fallbackToAgents: true
  }
);

Worker Registration

import { WorkerOrchestrator } from '@codmir/cloudflare-workers';

const orchestrator = new WorkerOrchestrator(config);

// Register workers
await orchestrator.registerWorker({
  id: 'worker-us-east-1',
  name: 'US East Worker',
  capabilities: ['text_processing', 'code_analysis'],
  region: 'us-east-1',
  status: 'idle'
});

// Execute distributed task
const result = await orchestrator.executeTask(
  'task_123',
  'code_analysis',
  'Analyze project dependencies',
  { files: ['package.json', 'src/**/*.ts'] }
);

Task Types

Supported Worker Tasks

  • analyze_file: File content analysis and metrics
  • validate_syntax: Code syntax validation
  • extract_imports: Import/dependency extraction
  • generate_docs: Documentation generation
  • format_code: Code formatting and combining
  • run_linter: Code linting and issue detection
  • fetch_api_data: API data fetching
  • transform_data: Data transformation and processing
  • generate_test: Test code generation
  • check_dependencies: Dependency analysis and security scanning

Task Division Examples

Code Analysis Task

Original: "Analyze all project files"
↓
Micro-tasks:
├── extract_imports (parallel per file)
├── validate_syntax (parallel per file)  
├── check_dependencies (depends on imports)
└── generate_docs (depends on all above)

File Processing Task

Original: "Process configuration files"
↓
Micro-tasks:
├── analyze_file (parallel per file)
└── transform_data (aggregate results)

Configuration

Environment Variables

# Cloudflare credentials
CLOUDFLARE_ACCOUNT_ID=your-account-id
CLOUDFLARE_API_TOKEN=your-api-token
CLOUDFLARE_SCRIPT_NAME=codmir-worker-minion

# Worker configuration
MAX_CONCURRENT_TASKS=100
TASK_TIMEOUT_MS=30000
LOAD_BALANCING_STRATEGY=least_loaded

# Integration settings
USE_WORKERS=true
FALLBACK_TO_AGENTS=true
WORKER_TASK_TYPES=code_analysis,file_processing,content_generation

Load Balancing Strategies

Least Loaded

{
  type: 'least_loaded'
}

Geographic

{
  type: 'geographic',
  config: { preferredRegion: 'us-east-1' }
}

Capability Based

{
  type: 'capability_based',
  config: { prioritizeSpecialized: true }
}

Deployment

Deploy Workers

# Install Wrangler CLI
npm install -g wrangler

# Login to Cloudflare
wrangler login

# Deploy worker minions
npm run deploy-worker

# Deploy to specific environment
wrangler deploy --env production

Worker Scaling

Workers automatically scale based on demand:

  • Cold Start: ~5ms for new worker instances
  • Concurrent Requests: Up to 1000 per worker
  • Global Distribution: Automatic edge deployment
  • Cost: Pay-per-request pricing model

Monitoring

Worker Health

const status = orchestrator.getStatus();
console.log({
  totalWorkers: status.totalWorkers,
  activeWorkers: status.activeWorkers,
  activeTasks: status.activeTasks,
  completedTasks: status.completedTasks
});

Performance Metrics

orchestrator.on('task_completed', (event) => {
  console.log(`Task ${event.taskId} completed in ${event.totalTimeMs}ms`);
});

orchestrator.on('worker_registered', (worker) => {
  console.log(`New worker: ${worker.id} in ${worker.region}`);
});

Benefits

Scalability

  • Edge Distribution: Workers run in 300+ locations worldwide
  • Automatic Scaling: No infrastructure management required
  • Parallel Execution: Massive parallelization of suitable tasks

Performance

  • Low Latency: Edge execution reduces network overhead
  • Fast Cold Starts: Workers start in milliseconds
  • Efficient Resource Usage: Pay only for actual execution time

Reliability

  • Fault Tolerance: Automatic failover between workers
  • Retry Logic: Configurable retry with exponential backoff
  • Graceful Degradation: Fallback to agent execution when needed

Cost Efficiency

  • Pay-per-Request: No idle server costs
  • Resource Optimization: Right-sized execution environments
  • Global Distribution: Reduced bandwidth costs

Integration with Existing System

The Cloudflare Workers integration seamlessly extends the existing agent orchestration system:

  1. Task Analysis: Existing PM Agent analyzes and enriches tasks
  2. Task Division: New Task Divider breaks suitable tasks into micro-tasks
  3. Hybrid Execution: Workers handle parallelizable tasks, agents handle complex operations
  4. Result Aggregation: Results from both systems are combined seamlessly
  5. Fallback Strategy: Failed worker tasks automatically fall back to agents

This creates a powerful hybrid system that leverages the best of both worlds: the intelligence and flexibility of agents with the scalability and performance of edge computing.