Token导航 LogoToken导航TokenDH.com
前端设计敏感数据github未标认证来源可访问许可证需确认审计通过

workersworkers 命令行

Agent Skill

workers 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

235

周安装

10

GitHub Stars

公开资料未说明

下载量

82
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:workers(workers 命令行)
来源仓库:https://github.com/null-shot/cloudflare-skills
仓库路径:skills/workers
安装命令:
npx skills add https://github.com/null-shot/cloudflare-skills --skill workers
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/null-shot/cloudflare-skills --skill workers

简介

用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中围绕仓库状态、代码变更或协作事项进行整理。
  • 通过 npx skills add 命令从指定 GitHub 仓库安装并使用。
  • 安装前建议确认权限范围和维护状态,注意可能触发联网、命令执行或文件读写操作。
  • workers 属于前端设计类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Cloudflare Workers

Essential patterns for building Cloudflare Workers applications with TypeScript, proper configuration, and Service Bindings for microservices.

FIRST: Project Setup

Initialize a new Workers project:

npm create cloudflare@latest my-worker
# OR
wrangler init my-worker

Minimal wrangler.jsonc:

{
  "name": "my-worker",
  "main": "src/index.ts",
  "compatibility_date": "2025-03-07",
  "compatibility_flags": ["nodejs_compat"],
  "observability": {
    "enabled": true,
    "head_sampling_rate": 1
  }
}

Code Standards

StandardRequirementNotes
LanguageTypeScript by defaultJavaScript only if explicitly requested
Module FormatES modules onlyNEVER use Service Worker format
ImportsAlways import types/classesMust import all used methods
File StructureSingle file unless specifiedKeep code in one file by default
DependenciesMinimize external depsUse official SDKs when available
Native BindingsNot supportedAvoid FFI/C bindings
TypesInclude TypeScript typesDefine Env interface for bindings

Handler Patterns

HTTP Request Handler (fetch)

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    const url = new URL(request.url);

    // Route handling
    if (url.pathname === "/api/data") {
      return handleAPI(request, env);
    }

    return new Response("Hello World!", {
      headers: { "Content-Type": "text/plain" }
    });
  }
};

async function handleAPI(request: Request, env: Env): Promise<Response> {
  // Validate request method
  if (request.method !== "POST") {
    return new Response("Method not allowed", { status: 405 });
  }

  try {
    const data = await request.json();
    // Process data...
    return Response.json({ success: true, data });
  } catch (error) {
    return Response.json(
      { error: "Invalid JSON" },
      { status: 400 }
    );
  }
}

Scheduled Handler (cron)

export default {
  async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {
    // Run scheduled tasks
    console.log("Cron triggered:", new Date(event.scheduledTime).toISOString());

    // Use waitUntil for background work
    ctx.waitUntil(performCleanup(env));
  }
};

async function performCleanup(env: Env): Promise<void> {
  // Background cleanup logic
  console.log("Cleanup completed");
}

wrangler.jsonc configuration:

{
  "triggers": {
    "crons": ["0 */6 * * *"]  // Every 6 hours
  }
}

Queue Consumer Handler

export default {
  async queue(batch: MessageBatch<QueueMessage>, env: Env, ctx: ExecutionContext): Promise<void> {
    for (const message of batch.messages) {
      try {
        await processMessage(message.body, env);
        message.ack();
      } catch (error) {
        console.error("Message processing failed:", error);
        message.retry();
      }
    }
  }
};

type QueueMessage = {
  id: string;
  data: unknown;
};

async function processMessage(body: QueueMessage, env: Env): Promise<void> {
  // Process queue message
  console.log("Processing message:", body.id);
}

Auto-Generate Environment Types

RECOMMENDED: Use wrangler types to automatically generate your Env interface from your wrangler.jsonc:

# Generate types from wrangler.jsonc
npx wrangler types

# Output to custom path
npx wrangler types ./types/env.d.ts

# Include runtime types (Wrangler >= 3.66.0)
npx wrangler types --experimental-include-runtime

This generates a worker-configuration.d.ts file with:

  • Env interface matching all your bindings (KV, R2, D1, secrets, etc.)
  • Runtime types matching your compatibility_date and compatibility_flags
  • Service binding types with full RPC method signatures

Add to tsconfig.json:

{
  "compilerOptions": {
    "types": ["@cloudflare/workers-types", "./worker-configuration"]
  }
}

When to regenerate:

  • After adding/removing bindings in wrangler.jsonc
  • After changing compatibility_date or compatibility_flags
  • After modifying.dev.vars (secrets)
  • Before deploying (run in CI/CD)

Example generated Env interface:

// worker-configuration.d.ts (auto-generated)
interface Env {
  // From wrangler.jsonc bindings
  MY_KV: KVNamespace;
  MY_BUCKET: R2Bucket;
  DB: D1Database;
  COUNTER: DurableObjectNamespace;
  AUTH_SERVICE: Service<typeof AuthService>;
  AI: Ai;
  MY_QUEUE: Queue;

  // From .dev.vars (secrets)
  DATABASE_URL: string;
  API_KEY: string;

  // From wrangler.jsonc vars
  ENVIRONMENT: "development" | "staging" | "production";
  API_VERSION: string;
}

Secrets Management

CRITICAL: Never put secrets in wrangler.jsonc! Secrets must be encrypted and hidden.

Secrets vs Environment Variables

TypeStorageUse ForVisibility
vars (wrangler.jsonc)PlaintextNon-sensitive config (URLs, flags)✅ Visible
secretsEncryptedAPI keys, passwords, tokens❌ Hidden

Local Development with.dev.vars

Create a .dev.vars file for local secrets (NEVER commit this file):

# .dev.vars (add to .gitignore)
DATABASE_URL="postgresql://localhost:5432/dev"
API_KEY="dev-key-12345"
STRIPE_SECRET="sk_test_..."

CI/CD Best Practice: Empty.dev.vars

For CI/CD and type generation, commit a .dev.vars with empty values:

# .dev.vars (committed to git)
# Real values set via: wrangler secret put
DATABASE_URL=""
API_KEY=""
STRIPE_SECRET=""

Why this works:

  • wrangler types reads .dev.vars to generate Env types
  • Empty values create correct TypeScript types
  • CI/CD can run type checking without real secrets
  • Production secrets are set via wrangler secret put or dashboard

Setting Production Secrets

Via Wrangler:

# Add/update secret (deploys immediately)
npx wrangler secret put API_KEY
# You'll be prompted for value

# List secrets (values never shown)
npx wrangler secret list

# Delete secret
npx wrangler secret delete API_KEY

Via Dashboard: Workers & Pages → Your Worker → Settings → Variables and Secrets → Add → Secret

Accessing secrets in code:

interface Env {
  DATABASE_URL: string;
  API_KEY: string;
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    // Access secrets from env (same as regular env vars)
    const db = new Database(env.DATABASE_URL);

    // Validate API key
    const key = request.headers.get("x-api-key");
    if (key !== env.API_KEY) {
      return new Response("Unauthorized", { status: 401 });
    }

    return Response.json({ success: true });
  }
};

Secret Store (Account-Level Secrets)

For secrets shared across multiple Workers:

{
  "secrets_store_secrets": [
    {
      "binding": "SHARED_API_KEY",
      "store_id": "abc123def456",
      "secret_name": "GLOBAL_API_KEY"
    }
  ]
}

Accessing Secret Store:

interface Env {
  SHARED_API_KEY: {
    get(): Promise<string>;
  };
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    // Secret Store requires .get() call
    const apiKey = await env.SHARED_API_KEY.get();
    return Response.json({ success: true });
  }
};

See references/secrets.md for complete secrets management guide.

wrangler.jsonc Configuration

Complete example with common bindings:

{
  "name": "my-worker",
  "main": "src/index.ts",
  "compatibility_date": "2025-03-07",
  "compatibility_flags": ["nodejs_compat"],

  "observability": {
    "enabled": true,
    "head_sampling_rate": 1
  },

  "vars": {
    "ENVIRONMENT": "production"
  },

  "kv_namespaces": [
    { "binding": "MY_KV", "id": "your-kv-id" }
  ],

  "r2_buckets": [
    { "binding": "MY_BUCKET", "bucket_name": "my-bucket" }
  ],

  "d1_databases": [
    { "binding": "DB", "database_name": "my-db", "database_id": "your-db-id" }
  ],

  "durable_objects": {
    "bindings": [
      { "name": "COUNTER", "class_name": "Counter" }
    ]
  },

  "queues": {
    "producers": [
      { "binding": "MY_QUEUE", "queue": "my-queue" }
    ]
  }
}

Key Configuration Rules:

  • Use wrangler.jsonc, NOT wrangler.toml
  • Set compatibility_date to current date (format: YYYY-MM-DD)
  • Always include compatibility_flags: ["nodejs_compat"]
  • Enable observability with head_sampling_rate: 1 for full logging
  • Only include bindings that are actually used in your code
  • Never include npm dependencies in wrangler.jsonc

See references/configuration.md for complete configuration options.

Background Tasks with waitUntil

Offload non-critical work to run after the response is sent:

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    // Return fast response
    const response = Response.json({ status: "accepted" });

    // Process in background (doesn't block response)
    ctx.waitUntil(performAsyncWork(request, env));

    return response;
  }
};

async function performAsyncWork(request: Request, env: Env): Promise<void> {
  // This runs after the response is sent
  const data = await request.json();
  await env.MY_KV.put("processed", JSON.stringify(data));
}

Use waitUntil for:

  • Analytics tracking
  • Cache warming
  • Logging
  • Non-critical database writes
  • Cleanup operations

Error Handling

HTTP Status Codes

async function handleRequest(request: Request, env: Env): Promise<Response> {
  try {
    // 400 - Bad Request
    if (!request.headers.get("content-type")) {
      return Response.json({ error: "Content-Type required" }, { status: 400 });
    }

    // 401 - Unauthorized
    const apiKey = request.headers.get("x-api-key");
    if (apiKey !== env.API_KEY) {
      return Response.json({ error: "Invalid API key" }, { status: 401 });
    }

    // 404 - Not Found
    const resource = await env.MY_KV.get("resource");
    if (!resource) {
      return Response.json({ error: "Resource not found" }, { status: 404 });
    }

    // 200 - Success
    return Response.json({ success: true, data: resource });

  } catch (error) {
    // 500 - Internal Server Error
    console.error("Request failed:", error);
    return Response.json(
      { error: "Internal server error" },
      { status: 500 }
    );
  }
}

Error Boundaries

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    try {
      return await handleRequest(request, env, ctx);
    } catch (error) {
      console.error("Unhandled error:", error);
      return Response.json(
        {
          error: "An unexpected error occurred",
          message: error instanceof Error ? error.message : "Unknown error"
        },
        { status: 500 }
      );
    }
  }
};

Service Bindings (Microservices)

Service Bindings are the recommended way to build multi-Worker architectures. They enable Worker-to-Worker communication with zero latency, no HTTP overhead, and no additional costs.

Why Service Bindings?

BenefitDescription
Zero latencyBoth Workers run on same thread/server by default
No HTTP overheadDirect RPC calls, not HTTP requests
Zero additional costSplit functionality without increasing bills
Type-safe RPCCall methods with full TypeScript support
Internal-only WorkersBuild services not exposed to public internet
Independent deploymentEach Worker deploys on its own schedule

RPC Interface (Recommended)

Export an RPC class from your service Worker:

// auth-service/src/index.ts
import { WorkerEntrypoint } from "cloudflare:workers";

export class AuthService extends WorkerEntrypoint<Env> {
  async validateToken(token: string): Promise<{ valid: boolean; userId?: string }> {
    const userId = await this.env.AUTH_TOKENS.get(token);
    return { valid: !!userId, userId: userId || undefined };
  }

  async createToken(userId: string): Promise<string> {
    const token = crypto.randomUUID();
    await this.env.AUTH_TOKENS.put(token, userId, { expirationTtl: 86400 });
    return token;
  }
}

// Must also export default handler for HTTP access (if needed)
export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    return new Response("Auth Service - use RPC interface");
  }
} satisfies ExportedHandler<Env>;

auth-service/wrangler.jsonc:

{
  "name": "auth-service",
  "main": "src/index.ts",
  "compatibility_date": "2025-03-07",
  "kv_namespaces": [
    { "binding": "AUTH_TOKENS", "id": "..." }
  ]
}

Calling the service from another Worker:

// api-worker/src/index.ts
interface Env {
  AUTH: Service<import("auth-service").AuthService>;
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const token = request.headers.get("Authorization")?.slice(7);

    if (!token) {
      return new Response("Unauthorized", { status: 401 });
    }

    // Call RPC method directly
    const result = await env.AUTH.validateToken(token);

    if (!result.valid) {
      return new Response("Invalid token", { status: 401 });
    }

    return Response.json({ userId: result.userId });
  }
};

api-worker/wrangler.jsonc:

{
  "name": "api-worker",
  "main": "src/index.ts",
  "compatibility_date": "2025-03-07",
  "services": [
    {
      "binding": "AUTH",
      "service": "auth-service"
    }
  ]
}

Generate types for Service Bindings:

# In api-worker directory
npx wrangler types

This auto-generates the Env interface with the correct Service<AuthService> type.

Fetch-Based Service Binding

For simpler use cases or when you don't need RPC:

// api-worker/src/index.ts
interface Env {
  AUTH: Fetcher;
}

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    // Forward request to auth service
    const authResponse = await env.AUTH.fetch(new Request("https://internal/validate", {
      method: "POST",
      body: JSON.stringify({ token: "..." })
    }));

    const result = await authResponse.json();
    return Response.json(result);
  }
};

See references/service-bindings.md for advanced patterns including environment-specific bindings and testing.

Detailed References

Best Practices

  1. Use TypeScript by default - Better type safety and IDE support
  2. Generate types with wrangler types - Auto-generate Env interface from config and.dev.vars
  3. NEVER put secrets in wrangler.jsonc - Use wrangler secret put or.dev.vars for local dev
  4. Use.dev.vars with empty values for CI - Enables type generation without exposing secrets
  5. Enable observability - Set observability.enabled: true for logging
  6. Use Service Bindings for microservices - Zero-cost, type-safe Worker-to-Worker calls
  7. Validate all inputs - Never trust user data
  8. Handle errors gracefully - Use try-catch and return appropriate status codes
  9. Use waitUntil for background tasks - Don't block response on non-critical work
  10. Keep bundle size small - Minimize dependencies for faster cold starts

Common Patterns

Complete API Worker

interface Env {
  MY_KV: KVNamespace;
  API_KEY: string;
}

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    try {
      // CORS preflight
      if (request.method === "OPTIONS") {
        return new Response(null, {
          headers: {
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "GET, POST, OPTIONS",
            "Access-Control-Allow-Headers": "Content-Type",
          }
        });
      }

      // Route handling
      const url = new URL(request.url);

      if (url.pathname === "/api/data" && request.method === "GET") {
        const data = await env.MY_KV.get("data");
        return Response.json({ data: data || null });
      }

      if (url.pathname === "/api/data" && request.method === "POST") {
        const body = await request.json();
        await env.MY_KV.put("data", JSON.stringify(body));
        return Response.json({ success: true });
      }

      return new Response("Not found", { status: 404 });

    } catch (error) {
      console.error("Request failed:", error);
      return Response.json(
        { error: "Internal server error" },
        { status: 500 }
      );
    }
  }
};

Middleware Pattern

type Middleware = (
  request: Request,
  env: Env,
  ctx: ExecutionContext,
  next: () => Promise<Response>
) => Promise<Response>;

const authMiddleware: Middleware = async (request, env, ctx, next) => {
  const apiKey = request.headers.get("x-api-key");
  if (apiKey !== env.API_KEY) {
    return new Response("Unauthorized", { status: 401 });
  }
  return next();
};

const loggingMiddleware: Middleware = async (request, env, ctx, next) => {
  console.log(`${request.method} ${request.url}`);
  const response = await next();
  console.log(`Response: ${response.status}`);
  return response;
};

function compose(...middlewares: Middleware[]) {
  return async (request: Request, env: Env, ctx: ExecutionContext): Promise<Response> => {
    let index = 0;

    const next = async (): Promise<Response> => {
      if (index >= middlewares.length) {
        return handleRequest(request, env);
      }
      const middleware = middlewares[index++];
      return middleware(request, env, ctx, next);
    };

    return next();
  };
}

export default {
  fetch: compose(loggingMiddleware, authMiddleware)
};

Resources

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

34.39%
按下载量换算28

Claude

31.25%
按下载量换算26

Cursor

19.05%
按下载量换算16

Gemini CLI

9.3%
按下载量换算8

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

敏感数据

该 Skill 可能接触密钥、Token、环境变量或敏感配置,应进入高风险复核队列,默认不自动发布。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills