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 withworkflows 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 doctorreports 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 statsreports runs and success rate per workflow for its current version, separate from runs of earlier versions.workflows failuresgroups 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 traceshows 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§
- Fixture
Call - One ordered command observation supplied to the offline executor.
- Fixture
Contract - Input/output schemas and effective local policy pinned by a fixture.
- Trigger
Receipt - Durable delivery receipt. Repeated admission returns the original receipt.
- Trigger
Request - An authenticated host delivery, deduplicated by its stable source event key.
- Trigger
Schedule - A durable fixed-interval schedule; missed intervals coalesce to the latest due one.
- Workflow
Bindings - Immutable execution-to-authority bindings in the host’s durable database.
- Workflow
Fixture - Portable, editable baseline for one named workflow and input.
- Workflow
Limits - Host-owned limits shared by every descendant of one root execution.
- Workflow
Triggers - Host boundary for authenticated webhooks and fixed-interval schedules.
- Workflows
- Builder for the workflows attached to one CLI.
Enums§
- Workflow
Database Kind - 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§
- Serve
Workflows - Method form of
serve, so a CLI’s entry point changes one word:cli.serve().awaitbecomescli.serve_workflows().await. - Workflow
Authority - Host authentication and revocation boundary for durable workflow calls.
- Workflow
Database - A tenant-owned database with atomic synchronous transactions.
- Workflow
Host - Host capabilities required by the shared workflow commands.
- Workflow
Sql - 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: exactlyCODEMODE_FLAGand nothing else. - serve
- Serves a CLI from process argv with workflows attached.
- serve_
attached servewith an author-configuredWorkflowsbuilder.- validate_
input - Validates a value against a schema, returning every violation found.