agentleFS
CloudflareKnown publishercloudflare/dynamic-workflows/AGENTS.md

dynamic-workflows

AGENTS.md44 starsChanged 7 months agoMITView on GitHub

dynamic-workflows is the glue between Cloudflare Workflows and Cloudflare Dynamic Workers. It lets a single dispatcher-owned workflow route run() calls to the correct tenant's dynamic worker, based on metadata the dispatcher attaches at create() time. Only these are re-exported from index.ts: Everything else in binding.ts / types.ts (wrapParams, unwrapParams, DispatcherEnvelope, WorkflowEventLike, WorkflowStepLike) is internal — kept purely so the library can type its own signatures without depending on a specific @cloudflare/workers-types version. Envelope encoding: wrapWorkflowBinding never merges metadata into the…

  • Installs packages
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.

    Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

The file

We split this AGENTS.md into the rules it gives an agent

2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Only these are re-exported from index.ts:

    line 33
  2. Very specific:

    Testable core: All real logic lives in dispatchWorkflow, which takes its env/ctx as plain arguments.

    line 75

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Developer Documentation

Overview

dynamic-workflows is the glue between Cloudflare Workflows and Cloudflare Dynamic Workers. It lets a single dispatcher-owned workflow route run() calls to the correct tenant's dynamic worker, based on metadata the dispatcher attaches at create() time.

Commands

pnpm install        # Install dependencies
pnpm run build      # Build the library
pnpm run test       # Run tests
pnpm run check      # Lint/format check

Repository Structure

packages/
├── dynamic-workflows/        # Main library
│   └── src/
│       ├── index.ts          # Public entrypoint — re-exports 4 functions/values + 4 types
│       ├── binding.ts        # wrapWorkflowBinding (+ internal wrapParams/unwrapParams helpers)
│       ├── entrypoint.ts     # createDynamicWorkflowEntrypoint, dispatchWorkflow
│       └── types.ts          # Public + internal TypeScript interfaces
├── tests/                    # Vitest + workerd tests
examples/
└── basic/                    # Minimal dispatcher demo with two hardcoded tenants

Public API surface

Only these are re-exported from index.ts:

  • Runtime: wrapWorkflowBinding, createDynamicWorkflowEntrypoint, dispatchWorkflow, MissingDispatcherMetadataError
  • Types: DispatcherMetadata, LoadWorkflowRunner, LoadWorkflowRunnerContext, WorkflowRunner

Everything else in binding.ts / types.ts (wrapParams, unwrapParams, DispatcherEnvelope, WorkflowEventLike, WorkflowStepLike) is internal — kept purely so the library can type its own signatures without depending on a specific @cloudflare/workers-types version.

Architecture

wrapWorkflowBinding(binding, metadata)
│
├─ .create({ params })      → binding.create({ params: { __dispatcherMetadata: metadata, params } })
├─ .createBatch(batch)      → same, applied to every item
└─ .get(id)                 → forwarded unchanged

Workflows engine → dispatcher.run(event, step)
│
└─ createDynamicWorkflowEntrypoint(loader)
    │
    └─ dispatchWorkflow({ env, ctx }, event, step, loader)
        │
        ├─ unwrapParams(event.payload)      — pulls metadata + params back out
        ├─ loader({ metadata, env, ctx })   — dispatcher picks the right runner
        └─ runner.run({ ...event, payload: params }, step)

Source Files

FilePurpose
index.tsPublic entrypoint — re-exports from the other files.
binding.tswrapWorkflowBinding and the envelope helpers (wrapParams, unwrapParams).
entrypoint.tsdispatchWorkflow (the core logic) and createDynamicWorkflowEntrypoint.
types.tsPublic TypeScript interfaces (DispatcherMetadata, WorkflowRunner, etc.).

Key Implementation Details

Envelope encoding: wrapWorkflowBinding never merges metadata into the user's params directly — it always wraps them in { __dispatcherMetadata, params }. This keeps tenant and dispatcher namespaces cleanly separated.

WorkflowEntrypoint subclassing: createDynamicWorkflowEntrypoint builds a real subclass of WorkflowEntrypoint from cloudflare:workers. The constructor cast is needed because TypeScript doesn't let us extends a generic class type directly; the runtime shape is a normal class.

Testable core: All real logic lives in dispatchWorkflow, which takes its env/ctx as plain arguments. The WorkflowEntrypoint subclass is a thin adapter over it. This is what lets tests cover the library without needing to trick workerd into instantiating a WorkflowEntrypoint in non-workflow contexts.

Testing

Tests run in workerd via @cloudflare/vitest-pool-workers:

  • binding.test.ts — Unit tests for wrapWorkflowBinding, wrapParams, unwrapParams.
  • entrypoint.test.ts — Unit tests for dispatchWorkflow + smoke tests for createDynamicWorkflowEntrypoint.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.