Skip to main content

Crate multicast_workflows

Crate multicast_workflows 

Source
Expand description

Durable Code Mode workflows attached to a multicast CLI as first-party commands.

A workflow is a Code Mode program with a name, a description, and an input schema. Workflows come from two sources and share one shape:

  • Shipped workflows are compiled into the binary by the CLI author with Workflows::shipped. Each becomes an ordinary top-level command, so it appears in help, --llms, skills, MCP tools, and the tool catalog.
  • Saved workflows are promoted at runtime from a completed execution with workflows save NAME --from EXECUTION_ID, and run with workflows run NAME.

Workflows::attach adds the shipped commands and a workflows group to a Cli. Workflows::attach_hosted uses a platform adapter instead of the default native SQLite store. Every run is a durable execution: a run that reaches an action needing approval stops with PAUSED_EXIT_CODE and its execution identifier, and workflows approve, workflows reject, and workflows resume continue it later, including from a new process.

Workflows call the CLI’s own commands through a connector built from the CLI’s commands before lifecycle commands are attached. codemode.workflows composes immutable workflow handles, including bounded recursive calls.

Input is validated against the workflow’s schema before the execution starts; invalid input runs no command. The schema checker supports a bounded keyword set (see check_schema) and rejects any other validation keyword at attach or save time.

With the default native feature, the local store holds an exclusive SQLite lock, so two processes of the same CLI cannot run workflows against one store at the same time.

§Maintaining a catalog

Every run of a named workflow is recorded in a run ledger beside the store, tagged with the workflow’s version: a digest of its program and input schema. The ledger outlives the store’s history pruning and feeds four read-only commands:

  • workflows doctor reports only what needs action: saved workflows that call commands the CLI no longer has, workflows whose current version keeps failing, runs interrupted mid-flight, and runs awaiting a decision. Each finding names the command that resolves it. Informational notices (never run, stale, duplicate, lost) appear only with --all. Exit code 1 means at least one error or warning.
  • workflows stats reports runs and success rate per workflow for its current version, separate from runs of earlier versions.
  • workflows failures groups failed runs by cause: the step that was executing and the error message with values (numbers, identifiers, quoted text) removed. A group is active until the workflow next succeeds.
  • workflows trace shows one execution’s steps, where it stopped, its error, console output, and status timeline, with large values truncated.

Ledger write failures are reported on stderr and never fail a run.

§Hosted workflows

Build with default-features = false and supply a WorkflowHost for execution, atomic SQL storage, timers, and fixtures. The standalone Cloudflare extension supplies CloudflareWorkflowHost with Durable Object SQLite and alarms. Hosts without a filesystem accept fixture JSON directly. The shared lifecycle, validation, diagnostics, retry, and trigger commands are unchanged.

§Agent archetypes

Workflows::archetype ships task guidance and a scope of commands and workflows as a top-level activation command. Operators can also persist definitions with archetypes save and retrieve their guidance with archetypes activate. Activation is advisory and executes no scoped command; all tools remain callable. Shipped guidance is also published as MCP prompts and in --llms-full; saved guidance stays behind activation.

§Serving a CLI

The native serve function replaces a CLI’s serve() call: it attaches the default workflows, and cli --codemode serves the Code Mode lifecycle tools over stdio against the CLI’s own commands. ServeWorkflows is its method form: an existing entry point changes cli.serve() to cli.serve_workflows().

Structs§

FixtureCall
One ordered command observation supplied to the offline executor.
FixtureContract
Input/output schemas and effective local policy pinned by a fixture.
TriggerReceipt
Durable delivery receipt. Repeated admission returns the original receipt.
TriggerRequest
An authenticated host delivery, deduplicated by its stable source event key.
TriggerSchedule
A durable fixed-interval schedule; missed intervals coalesce to the latest due one.
WorkflowBindings
Immutable execution-to-authority bindings in the host’s durable database.
WorkflowFixture
Portable, editable baseline for one named workflow and input.
WorkflowLimits
Host-owned limits shared by every descendant of one root execution.
WorkflowTriggers
Host boundary for authenticated webhooks and fixed-interval schedules.
Workflows
Builder for the workflows attached to one CLI.

Enums§

WorkflowDatabaseKind
Isolated workflow databases supplied by a host.

Constants§

ARCHETYPES_GROUP_NAME
Name of the command group that manages archetypes.
CODEMODE_FLAG
The only argument that starts the Code Mode MCP server over stdio.
GROUP_NAME
Name of the command group that manages workflows.
MAX_FIXTURE_BYTES
Maximum serialized fixture size accepted by capture and check (16 MiB).
PAUSED_EXIT_CODE
Process exit code for a workflow run awaiting approval or host reconciliation.

Traits§

ServeWorkflows
Method form of serve, so a CLI’s entry point changes one word: cli.serve().await becomes cli.serve_workflows().await.
WorkflowAuthority
Host authentication and revocation boundary for durable workflow calls.
WorkflowDatabase
A tenant-owned database with atomic synchronous transactions.
WorkflowHost
Host capabilities required by the shared workflow commands.
WorkflowSql
Synchronous SQL operations; callbacks must never yield to another request.

Functions§

check_schema
Confirms that a schema uses only keywords this checker enforces.
codemode_service
Starts a Code Mode service whose only connector is the CLI’s own commands.
default_store_path
Returns the default workflow store for a CLI.
is_codemode_request
Returns whether argv (without the program name) requests the Code Mode server: exactly CODEMODE_FLAG and nothing else.
serve
Serves a CLI from process argv with workflows attached.
serve_attached
serve with an author-configured Workflows builder.
validate_input
Validates a value against a schema, returning every violation found.