feat(examples): prompt-lab — the Prompt Lab product brief as one relayflow
The Prompt Lab product brief (automated prompt setup and issue-fix for home-health chart drafting) as a v2 relayflow, proven end to end locally with real Claude calls.
What it is
examples/prompt-lab/prompt-lab.flow.ts takes a job input:
job | Brief section |
|---|---|
new-agency | Job 1: sharing piles → first-pass prompts (Prompt QA) → test planner → run on shelf patients → you edit the grid (saved as targets) → iterate on changed rows → shared rows go to the question manager → you commit all / only / all except |
fix | Job 2: shelf patients → current outputs → you set gold → iterator → Prompt QA → re-run and score (% worked, per patient) → you mark done (= live; warns when shared) |
patient | Test patient creator: gap brief → plan → you kick generate → Patient QA loop → lock onto the shelf |
- Each job file follows its diagram in the brief step by step.
- Every You box is
f.human(…, { to: input.reviewer }).revieweris required, with no default person. - Apricot's Bank is a local JSON lab written only by
store.ts, whose verbs are all idempotent. Every read and write is a journaledf.run. - The deterministic logic (piles, menus, highlights, changeset, score, commit selection, identifier floor, reply schema) and the store (idempotency, compare-and-swap publish, OS-released lab lock, byte limit) are unit-tested: 23 tests,
npm test.
Proof
prove.sh seeds a fresh lab and runs all three jobs through the real kernel (flows run --local-agent). It stops on the first exit code it didn't expect. At each gate it applies the reviewer's edit (captured as a diff), then runs flows answer / flows resume. Everything is captured in evidence/run/:
| Run | Result |
|---|---|
| Job 1 | 28 steps, completionReason: success. living-situation went live. ostomy-supplies had no shelf patient, so it wasn't offered and stays a draft. The wound row went to the question manager with its target |
| Patient | 14 steps, success. Patient QA sent the chart back before one passed; roderick locked onto the shelf |
| Job 2 | 24 steps, success. The live prompt answered Pat "Healed / High", the brief's failure; after the rewrite Pat worked. 3 of 4 golded patients worked (75%): roderick did not. The shared warning named harbor, maple and sunrise. The scripted reviewer marked done; the README explains why a human would look at roderick first |
The README says what the proof does and doesn't show. The reviewer is a script, not a clinician, and the multi-menu re-run is covered by a unit test only.
Runtime findings
Captured under evidence/runtime-findings/; the workarounds are commented in the code:
- Concurrent
f.llmloses the run. The flow runs model calls one at a time instead. - A predicate
.gate(fn)can't be resumed. Fixed in #558; the flow does its checks in the body until that ships. - A fenced JSON reply fails a structured
f.llm. Fixed in #558; until then the flow uses text-formf.llmplus its own schema check. - A lease renewal racing a completion can kill a run.
Findings 1 and 4 are tracked as garden-ready issues.
Local only: Cloud receives a single authored source, and this example imports sibling modules.
Review
First round, fixed in 735f2e06: store lock, per-menu re-run, visit type, gap keys, UTF-8 byte limit, content-keyed plan file, prove.sh exit codes, and commit candidates requiring coverage. Codex re-review, fixed in 8609ab8e: compare-and-swap publish, an OS-released SQLite lock, and removing the unread config-level proposal. Each thread has a reply, and the store fixes are mutation-verified in evidence/review/. The proof and evidence were regenerated on 8609ab8e.
🤖 Generated with Claude Code
[!NOTE]
Low Risk
Additive example under examples/ with no core runtime changes; main operational caveat is publishing shared prompts locally via the lab store, which is intentional demo scope.
Overview
Adds examples/prompt-lab, a runnable relayflow that implements the Prompt Lab product brief for home-health chart prompt setup and repair.
prompt-lab.flow.ts dispatches three jobs via a required reviewer and local lab directory: new-agency (sharing piles, first-pass prompts with Prompt QA, test planner, review grid → targets, iterate agency-specific rows, route shared/mismatch rows to issues, commit live prompts), fix (gold from grid, iterator + Prompt QA, re-run/score per distinct agency menu, compare-and-swap publish), and patient (gap brief → plan → generate with Patient QA and PHI checks → lock shelf patient). All lab I/O goes through journaled f.run calls to store.ts (idempotent verbs, SQLite exclusive lock, write-new that does not overwrite reviewer edits).
Supporting code includes deterministic lib/ helpers (piles, grid highlights, scoring, commit modes, reply parsing), fixtures/, prove.sh plus evidence/run/ capturing a full local-agent proof, and evidence/runtime-findings/ documenting relayflows workarounds (sequential LLM, text LLM + schema validation instead of structured output, failStep instead of predicate gates).
Reviewed by Cursor Bugbot for commit 90f56b68bd902b5b34ab4dde5e4191d730e3f063. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Adds the Prompt Lab product brief as one end-to-end relayflow example in examples/prompt-lab.
The flow implements the brief's three jobs — new-agency prompt setup, question-level prompt fixes, and a test-patient creator — mapping System boxes to steps, You boxes to reviewer gates, and Outcome boxes to lab-store writes. prove.sh seeds a fresh local lab and runs all three jobs with real model calls; 16 unit tests cover the pure logic. A short README covers setup and running; PROOF.md carries the design notes and proof.
Notable behaviors
- Job 1 plans from shelf patients of the run's visit type; gap briefs carry that visit type and are keyed per question × visit type.
- Job 2 re-runs and scores against every distinct menu the question is asked with, since a done change applies to all of them.
- Job 2 iterates from the live prompt with the changeset; config level no longer pays for a proposed rewrite of shared rows nothing read.
- Only first-pass prompts that ran on a covered patient are commit candidates; gap-only drafts stay held until a patient covers them.
- Job 2 checks shelf coverage after filtering and closes an issue the live prompt already resolves.
- Concurrent runs are safe: the store's mutating verbs take a SQLite
BEGIN EXCLUSIVElock the kernel releases when its process dies,publishis a compare-and-swap on the live prompt, and the patient plan file is keyed by the plan so a re-run never reuses a stale one.
Runtime findings
- Model calls run serially because concurrent
f.llmsteps lose the run; gate checks run in the body and replies are text-form with an author-side schema check, since predicate gates can't be resumed and fenced JSON fails structuredf.llm. - A lease renewal racing a completion can kill a run; workarounds point at relayflows issues #558, #560, #561.
Local only: Cloud receives a single authored source, and this example imports sibling modules.
Agent Relay sessions
claudesessiondf229951· opened viagh pr create· last active 2026-09-23