Workflow state machines, context handoff, code execution, and feedback
These tools manage multi-step workflows with state machines, enable context handoff between sessions, execute code in sandboxed environments, and collect quality feedback for continuous improvement.
Tools Overview
| Tool | What It Does |
|---|---|
ctx_workflow | Workflow rails (state machine + evidence). Actions: start|status|transition|complete|evidence_add|evidence_list|stop. |
ctx_handoff | Context Ledger Protocol (hashed, deterministic, local-first). Actions: create|show|list|pull|clear. |
ctx_execute | Run code in sandbox (11 languages). Only stdout enters context. Raw data never leaves subprocess. Languages: javascript, typescript, python, shell, ruby, go, rust, php, perl, r, elixir. |
ctx_feedback | Harness feedback for LLM output tokens/latency (local-first). Actions: record|report|json|reset|status. |
ctx_pack | PR Context Pack. action=pr yields changed files, related tests, impact summary, and relevant context artifacts. |
ctx_proof | Export a machine-readable ContextProofV1 (Verifier + SLO + Pipeline + Provenance). Writes to .lean-ctx/proofs/ by default. |
ctx_workflow
ctx_workflow implements state-machine-driven workflows for complex multi-step tasks.
Define named workflows with ordered steps, transition between states, and enforce evidence collection
at each stage.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
action | string | No | Workflow operation to perform |
name | string | No | Workflow name (for create/start) |
key | string | No | Workflow key / identifier |
spec | string | No | Workflow specification (JSON) |
to | string | No | Target state for transition |
value | string | No | Evidence value for the current step |
Example: Bug Fix Workflow
ctx_workflow action="start" name="bugfix" spec='{"steps":["reproduce","diagnose","fix","test","verify"]}'
→ Workflow bugfix started at step: reproduce
ctx_workflow action="transition" key="bugfix" to="diagnose" value="Reproduced in test_auth.rs:42"
→ bugfix: reproduce → diagnose (evidence saved) ctx_handoff
ctx_handoff enables context transfer between sessions or agents. Save your current
context (files, decisions, progress) and restore it in a new session without re-reading everything.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
action | string | No | Handoff operation |
path | string | No | Path for save/load |
paths | string[] | No | Multiple paths to include |
apply_knowledge | boolean | No | Include knowledge base in handoff |
apply_session | boolean | No | Include session state |
apply_workflow | boolean | No | Include workflow state |
Example: Save & Restore Context
# Save current context before ending session
ctx_handoff action="save" apply_knowledge=true apply_session=true
→ Context saved: 12 files, 3 knowledge entries, 1 workflow
# In new session: restore everything
ctx_handoff action="load"
→ Restored: 12 cached files, 3 knowledge entries, workflow "bugfix" at step "test" ctx_execute
Run code in sandboxed subprocesses across 11 languages. See the full ctx_execute documentation for language support and examples.
ctx_feedback
ctx_feedback records quality signals about tool usage - latency, token counts, model info,
and free-form notes. This data feeds into LeanCTX's adaptive optimization over time.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
action | string | No | Feedback operation |
intent | string | No | What the agent was trying to do |
model | string | No | LLM model name |
latency_ms | number | No | Time taken in milliseconds |
llm_input_tokens | number | No | Input token count |
llm_output_tokens | number | No | Output token count |
note | string | No | Free-form quality note |
ctx_pack v3.4.5
ctx_pack generates a PR Context Pack: changed files, related tests, impact summary, and relevant context artifacts - ideal for code reviews and handoffs.
| Param | Type | Req | Description |
|---|---|---|---|
action | string | No | pr (default) - generate PR pack |
output | string | No | Output directory (default: stdout) |
ctx_proof v3.4.5
ctx_proof exports a machine-readable ContextProofV1 artifact containing verifier results, SLO evaluations, pipeline metrics, and provenance data.
Proofs are written to .lean-ctx/proofs/.
| Param | Type | Req | Description |
|---|---|---|---|
format | string | No | json (default) or html |