Run a business process everyone can actually see.
Your coding agent builds the steps and Trestle draws every path and run.
Describe what needs to happen in plain English, or write it yourself as one ordinary TypeScript function. Trestle runs it through crashes, deploys, and months-long waits, keeping the diagram generated straight from the code. It ships as a library over your own database, with no vendor server to run or rent.
claim 1042
engine 1engine 2
To your coding agent
Build a process for handling insurance claims. First get an appraisal, and if the claim is higher than that, wait up to three days for an adjuster to approve it and refuse it if they don’t. Pay the claim if it’s approved or within the appraisal, and make sure it never gets paid twice.
The code, 27 lines
const value = await act({
name: 'Appraise the claim',
body: () => surveyor.appraise(policy),
});
const isOver = await choice({
name: 'Over the appraisal?',
condition: amount > value,
});
if (isOver) {
const review = await wait({
name: 'Adjuster approves',
party: adjuster,
window: '3 days',
});
const isApproved = await choice({
name: 'Approved?',
condition: review.isAnswered && review.answer === true,
});
if (!isApproved) {
return 'refused';
}
}
await act({
name: 'Pay the claim',
body: ({ actKey }) => bank.pay(amount, actKey),
});
return 'paid';The claim, drawn
From the start, appraise the claim, then ask whether it is over the appraisal. Yes leads to the adjuster, who has 3 days to approve it; answered or not, the next question is whether it is approved: yes leads to paying the claim, no ends refused. A claim not over the appraisal goes straight to paying it, which ends paid. Appraising and paying each end failed if they fail.
no3 days, no answernofailsfailsyesansweredyesThe claim, drawn
From the start, appraise the claim, then ask whether it is over the appraisal. Yes leads to the adjuster, who has 3 days to approve it; answered or not, the next question is whether it is approved: yes leads to paying the claim, no ends refused. A claim not over the appraisal goes straight to paying it, which ends paid. Appraising and paying each end failed if they fail.
no3 days,no answernofailsfailsyesansweredyes- You start by explaining what should happen in your own words. Any project started with
npm create @trestlerunalready includes the instructions, lint rules, and tests your coding agent needs. - The agent writes one async TypeScript function using Trestle’s
act,wait, andchoicesteps alongside plainifstatements. Because it is ordinary code, your team can read it and change it safely with tests. - Nobody drew this diagram by hand. Trestle builds it straight from the function, mapping every branch, the three-day timeout, and all three endings to the lines of code sitting beside it.
- Claim 1042 arrives above its appraisal. Trestle records each step before it starts.
- Three days went by with no reply, so the claim took the timeout path from the code and closed as refused.
- The first engine died mid-payment, so nobody knew whether the bank had taken it. A second engine resumed from the last saved step and retried with the same
actKey; the bank matched the key, leaving one payment on the ledger. - That one function ran the claim, generated the diagram, and recorded every step along the way.
npm create @trestlerun already includes the instructions, lint rules, and tests your coding agent needs.The agent writes one async TypeScript function using Trestle’s act, wait, and choice steps alongside plain if statements. Because it is ordinary code, your team can read it and change it safely with tests.Nobody drew this diagram by hand. Trestle builds it straight from the function, mapping every branch, the three-day timeout, and all three endings to the lines of code sitting beside it.Claim 1042 arrives above its appraisal, and you can watch it move across the diagram. Trestle records each step before it starts.Now the claim is waiting on an adjuster, and for this demo that’s you. The three-day window is sped up to a few seconds, so choose whether to approve or refuse it before time runs out.Your approval is recorded, and the claim moves on to payment.Your decision is recorded, and the claim closes as refused.Three days went by with no reply, so the claim took the timeout path from the code and closed as refused.The payment is on its way to the bank now. Try killing the engine before it finishes to see what happens.The first engine died mid-payment, so nobody knew whether the bank had taken it. A second engine resumed from the last saved step and retried with the same actKey; the bank matched the key, leaving one payment on the ledger.The payment cleared on the first try. Run it again and kill the engine mid-payment to see how Trestle handles a crash.What do you care about?
- Code that survives crashes and long waitsSee how Trestle saves progress in your own database, whether you are moving off queues and cron jobs or coming from Temporal, Restate, Inngest, or Step Functions.
- Showing everyone how the process worksSee how Trestle draws every branch and timeout directly from the code so business owners and people used to BPMN read the same diagram as engineers.
- Putting AI agents to workSee how coding agents author and verify processes, operate live runs over MCP, and make decisions inside rules they cannot rewrite.
- Processes that wait on peopleSee how approvals and sign-offs become inbox tasks with generated forms, reminders when they run late, and clear fallback paths when nobody responds.
- Keeping runs moving when things get stuckSee the web console for checking where every active run stands and fixing stuck work without calling an engineer.
- Rules that must never be brokenSee how Trestle checks and enforces separation of duties and required approvals, and logs requested changes, who asked, and the outcome where nothing can edit them.
- How the code and tests are writtenSee how to write processes in plain async/await, Effect, RxJS, or state machines, with typed schemas and tests that move the clock weeks ahead without waiting.
- What is proven and what is notSee the deterministic simulation tests, the named engine guarantees, and the plain list of what Trestle does not promise.
Everything Trestle includes.
Writing processes
- Write a process as ordinary async TypeScript with standard control flow.
- Use async/await, Effect, RxJS, or state machines—all run and draw alike.
- Validate inputs, answers, and outcomes with Zod, Valibot, or Standard Schema.
- Generate live diagrams linked to source lines, with Mermaid export and diffs.
- Start coding agents with built-in instructions, lint rules, and diagram checks.
- Call processes from any language via OpenAPI HTTP or a
fetchclient.
Building blocks
- Three core steps:
actfor work,waitfor responses,choicefor decisions. - Run branches in parallel, race them, or take the first success.
- Undo cancelled or losing branches, with cleanup steps run to completion.
- Call another process directly, or start a separate one once.
- Loop over collections while capping how many items run at once.
- Poll external systems, schedule timers, and put deadlines on any part.
Messages and timing
- Send messages to active runs, taking duplicate IDs only once.
- Start or advance runs from signed Stripe, Slack, GitHub, or Shopify webhooks.
- Feed runs from queues with recipes for SQS, Kafka, and NATS.
- Start runs on a schedule where duplicate ticks create one run.
- Wait for minutes or months with nothing kept in memory.
- Cap concurrency or rate limits for a step across all runs.
People
- Turn human waits into inbox tasks with forms built from schemas.
- Notify through your provider, with one reminder when a task is late.
- Reassign tasks anytime, or from your late-task notifier, alerting both people.
- Open a single task directly for one person via a signed link.
- Take an explicit fallback path on timeout, taking duplicate answers once.
- Scope tasks by relationship so managers only answer for their own team.
AI agents
- Coding agents write plain TypeScript processes and verify them against tests.
- Operate runs over MCP, starting read-only; agent changes log under whoever asked.
- Put process decisions to an agent that picks drawn options with reasons.
- Block forbidden options with rules the deciding agent sees and cannot change.
- Bound multi-turn agent tool loops so they stay readable on the diagram.
- Track step metrics like tokens and cost using your own models.
Operations
- List every run in the console with a plain summary of status.
- Retry steps, restart from earlier points, supply results by hand, or cancel.
- Preview and apply operator fixes across many runs at once.
- Run the same actions from the console, CLI, HTTP API, or MCP.
- Measure step counts, timing, retries, and spend, and compare across releases.
- Export OpenTelemetry traces and metrics, JSON logs, and signed event webhooks.
Safe deploys
- Choose per process whether unfinished runs adopt new code, finish, or pause.
- Run a pre-deploy check predicting every unfinished run’s outcome without executing work.
- Move active runs onto new code without repeating finished steps unasked.
- Declare renamed steps so existing run history follows the new name.
- Spot paths on the diagram that no real run has ever taken.
Testing
- Test processes with stand-in systems and jump the clock weeks ahead.
- Fail tests automatically when Trestle detects side effects outside a step.
- Generate tests covering every branch and report any unreachable diagram edge.
- Record a production run and replay it against new process code.
- Simulate crashes at every save, failing stores, and concurrent engines.
- Drive real web pages inside a process through Playwright.
Rules and access
- Declare rules for step order, bans, per-run limits, and separation of duties.
- Check rules before deploy and enforce them live, with one-time owner overrides.
- Pass system credentials to a step only where that work is declared.
- Pause steps or processes with a lock without deploying or burning deadlines.
- Require authentication by default with seven scopes and hashed, rotating keys.
- Uneditable audit log of requested changes, who asked, how, and the answer.
Where it runs
- Just a library and your database, with no vendor server to run.
- Store state in SQLite, Postgres (including behind PgBouncer), memory, or browsers.
- Run on Node, edge runtimes, browsers, and Web Workers.
- Host on one server, containers, Cloudflare, AWS Lambda, or Cloud Run.
- Hand individual steps off to external workers or specialised services.
- Retry interrupted steps with
actKey, bound retries by time, or pause them.
How Trestle is tested.
A deterministic simulator runs several engines over one store, crashes them and fails the store, and checks more than seventy named invariants after every turn. Dedicated crash tests kill active runs immediately before and after every save to verify that saved progress survives and each finishes with the same record as one left alone. Every failure the simulator finds is kept as a replayable test that every future commit has to pass.
What Trestle promises
- Saved progress survives a crash, and completed steps are answered from the record instead of running again.
- Every attempt of an
actreceives the exact sameactKey, even if you later rename the step. - Messages sent under the same ID, duplicate task answers, and child process starts are each accepted once.
- Business rules declared on a process are checked against the diagram before deploy and enforced during each run.
What Trestle does not promise
- Side effects written outside a step will run again on replay, though Trestle’s tests fail on any they detect.
- An external system that ignores the
actKeyyou pass it can still perform the work twice. - Decisions hidden outside a
choicewill not appear on the diagram and are only caught if a live run leaves the map. - Rules only govern the steps and choices your process declares, not code outside them.
Start a project.
npm create @trestlerunTrestle is open source under the MIT licence.
Your visit is running on Trestle.
This is the real Trestle engine running a live process in your browser tab, not a simulation. Each of the eight topic pages you open answers its question once, showing the path you have taken and the pages you have not opened yet—until you copy npm create @trestlerun to finish it.
Your path so far
npm create @trestlerunYou have opened all eight pages. Copy npm create @trestlerun whenever you are ready to finish the process.
You copied npm create @trestlerun, so this process has finished and recorded your full visit.
Show the code and detailsHide the code and details
export const visit: Process<undefined, string> = process({
name: 'visit',
body: async () => {
for (const _lap of Object.keys(CASES)) {
const next = await choice({
name: 'What do you care about?',
party: visitor,
cases: CASES,
});
if (next === START) {
return 'started a project';
}
}
return 'never started a project';
},
});export const visit: Process<undefined, string> =
process({
name: 'visit',
body: async () => {
for (const _lap of Object.keys(CASES)) {
const next = await choice({
name: 'What do you care about?',
party: visitor,
cases: CASES,
});
if (next === START) {
return 'started a project';
}
}
return 'never started a project';
},
});export const visit: Process<
undefined,
string
> = process({
name: 'visit',
body: async () => {
for (const _lap of Object.keys(
CASES,
)) {
const next = await choice({
name: 'What do you care about?',
party: visitor,
cases: CASES,
});
if (next === START) {
return 'started a project';
}
}
return 'never started a project';
},
});Your answers and the run are stored only in this browser.
npm create @trestlerun