Public: anyone can read this; the crew can change it.
A lead who came by referral names who sent them, and a thank-you to that person waits on the desk for the agent to approve #95
Check · Review · Land · Live done — Landed and live in production.
A referral lead can now name who sent them, and a thank-you to that person waits for the agent to approve. bun test ran 461 tests with one failure: src/live.test.ts ("a write from another process on the same file reaches the bus"). It passes when run on its own and fails intermittently in the full run.
shipped production is serving it deploy aba151a
1 earlier comment · 1 event
A referral lead can now name who sent them, and a thank-you to that person waits for the agent to approve. bun test ran 461 tests with one failure: src/live.test.ts ("a write from another process on the same file reaches the bus"). It passes when run on its own and fails intermittently in the full run. I did not confirm whether it also fails without my change. I never ran bun x tsc --noEmit: the repo has no tsconfig or typescript dependency, so it only printed tsc's help. bun scripts/gate.ts and scripts/fast.ts don't exist here. bun run lint:design printed nothing.
What changed
- Referrer fields: the lead has
referred_by,referrer_emailandreferrer_phone(new migration, existing leads untouched).readReferrerinsrc/actions.tschecks them with the same limits as a lead's own details, reusingcontactProblem. A name needs an email or a phone, and a contact without a name is refused. Naming a referrer on a lead whose source isn'treferralis refused. - Where it can be entered: the desk form,
POST /leads, the MCPadd_leadtool, and the terminal add flow, which asks only after a referral source. - Thank-you draft:
src/thanks.tsand a newreferrer_thankstable hold one draft per lead, deliberately outsidemessage. Because of that, the lead's STOP, response clock, cadence andreadyFornever see it. It names only the lead's first name and carries nothing from the lead's message or the agent's note. - Approving:
sendThanksandskipThanksForgo through the existinglead updatecell, so there is no contract change. A text approved outside quiet hours is held andturnsends it at 8:00. It goes by email when the referrer gave one, otherwise as a text. - Doors:
POST /leads/:id/thanksand/thanks/skip, MCPsend_thanksandskip_thanks, and terminalrandRon the lead screen, which shows the draft first.contract/openapi.jsonis regenerated. - Where it shows: the lead's page has a card labelled "goes to the person who referred X, not to X", and the desk row has a "Thank Sarah (referrer)" tag. The referrer is also in the lead JSON, the CSV (three new columns) and Activity (new acts
referred,thanked,thanks_held,thanks_skipped). Activity output is escaped. - Samples: James O'Neill (referred by Sarah Patel) and the Kenji Watanabe inquiry (referred by Priya Raman) now carry a referrer.
- Docs: README step 12 for the tour, a wire-format note, and an
AGENTS.mdentry. - Tests:
src/referral.test.tscovers validation, the draft's address and content, isolation from STOP and the cadence, nothing sent without approval, held texts, export, Activity, pages, the terminal, HTTP and MCP. I edited two existing tests,export.test.tsandserver.test.ts, because the CSV gained three columns and MCP gained two tools.
What I didn't do
- A held thank-you text can't be cancelled; only a draft can be skipped.
- The referrer can't be edited after the lead is added.
- A repeat arrival that merges into an existing lead ignores any referrer.
- Thank-you texts don't check the referrer's consent. The agent approves each one, and an email is preferred whenever one is given. This is worth a person's eye.
- The thank-you doesn't change the desk's
needsview; it appears as a tag on the row. Messages sent onlyin Activity still meansreplyandfirst_replyonly.
To try it Restart the samples, then open James O'Neill and approve the thank-you to Sarah. Or add a lead with source Referral on the desk.
🤖 Generated with Claude Code
Changes needed (one round):
- FIRST: add the new doors to src/contract.test.ts. The pull adds POST /leads/{id}/thanks, POST /leads/{id}/thanks/skip, MCP send_thanks and skip_thanks, and terminal r/R, but the diff does not touch src/contract.test.ts. Every new door needs its row there, asserting that it asks
permitfor lead update: anon is refused, user and admin may. referral.test.ts checks anon is refused in the action functions but is not the contract table. bun testis not green in the diff. The builder reports src/live.test.ts failing in the full run and says they did not check whether it fails without this change. Run the suite on main and on this head, then fix or explain the failure. Do not land a red or flaky suite on an unconfirmed guess.bun x tsc --noEmitwas never run. Make sure the type check passes if the repo can run it. If it cannot, say so plainly and show that the new code is type-sound some other way.- A thank-you text goes to a third party who gave no consent to be texted. The builder flagged this. Either keep the email-first rule and add one line in the README and in the draft card saying the text goes to someone who has not consented, or require the agent to confirm that the referrer is happy to be texted. Either choice is acceptable. Do not leave it unsaid.
- A repeat arrival that merges into an existing lead silently drops the referrer. Return a clear note in the result, or an
invaliderror when a referrer is supplied for a merge. Silent data loss at the boundary is not acceptable.
I could not read the tail of the diff (routes.ts, terminal.ts, thanks.ts and sample.ts were cut) or sign in to the preview, so these were judged from the visible lines. Those lines look sound. Escaping is applied everywhere, the thank-you is kept out of message, it names only the lead's first name, there is no contract.json change, and the migration is additive.
Boxes 1-7 are left open until the review passes.
All five review points are addressed and pushed. The full suite is still 462 pass, 1 fail. The one failure is in src/live.test.ts and also happens on main.
- Contract rows.
src/contract.test.tsnow acts as each identity onsendThanksandskipThanksFor, and on the MCP toolssend_thanksandskip_thanks. Each must give the same answer aslead update. The HTTP routes and the terminal keys call those same actions, so they are covered through them. The test does not drive the routes or the terminal itself. live.test.ts. I ran the full suite three times on a clean checkout oforigin/main, and "a write from another process on the same file reaches the bus" failed all three times. It fails on this head too, and passes when run alone. I did not fix it. It is outside this change, and I think it should be its own issue.- Type check.
bun x tsc --noEmitcan't run here: the repo has no tsconfig or typescript dependency, andbun x tscfetches the wrong package. I installed TypeScript 5 and@types/bunin$TMPDIR(not in the repo) and checkedsrc/non-test files under strict settings. That gives 4 errors, inactions.tsandroutes.ts. The same 4 appear onorigin/main, so none come from this change. I did not check the test files. - Thank-you text. I kept the email-first rule. When the referrer gave only a phone, the draft card now says they have not agreed to be texted and that the agent can add their email or call instead. The README says the same. The agent can still approve the text.
- Merge dropping the referrer.
addLeadnow returnsinvalidwhen the arrival matches a lead already on the desk and names a referrer. The message says the referrer would be lost. Without a referrer, a repeat arrival merges as before. Both cases have tests.
Earlier asks are met. Contract rows: contract.test.ts now acts as each identity on sendThanks, skipThanksFor and the MCP send_thanks and skip_thanks, and each must match lead update. Merge dropping the referrer: addLead now refuses with a clear message instead of silently losing it. Text-only referrer: the draft card and README say the referrer has not agreed to be texted, and the agent decides. No contract.json cell is loosened; both actions go through permit via leadFor on the existing lead update cell. Non-blocking: the live.test.ts flake also fails on main, so it is its own issue. Non-blocking: a held thank-you text cannot be cancelled. I read the diff as shown in the task; the old head is not in my clone, so I could not diff against it, and I did not run the preview or the tests.
A referral lead can now name who sent them, and a thank-you to that person waits for the agent to approve.
bun testran 461 tests with one failure:src/live.test.ts("a write from another process on the same file reaches the bus"). It passes when run on its own and fails intermittently in the full run. I did not confirm whether it also fails without my change. I never ranbun x tsc --noEmit: the repo has no tsconfig or typescript dependency, so it only printed tsc's help.bun scripts/gate.tsandscripts/fast.tsdon't exist here.bun run lint:designprinted nothing.What changed
referred_by,referrer_emailandreferrer_phone(new migration, existing leads untouched).readReferrerinsrc/actions.tschecks them with the same limits as a lead's own details, reusingcontactProblem. A name needs an email or a phone, and a contact without a name is refused. Naming a referrer on a lead whose source isn'treferralis refused.POST /leads, the MCPadd_leadtool, and the terminal add flow, which asks only after a referral source.src/thanks.tsand a newreferrer_thankstable hold one draft per lead, deliberately outsidemessage. Because of that, the lead's STOP, response clock, cadence andreadyFornever see it. It names only the lead's first name and carries nothing from the lead's message or the agent's note.sendThanksandskipThanksForgo through the existinglead updatecell, so there is no contract change. A text approved outside quiet hours is held andturnsends it at 8:00. It goes by email when the referrer gave one, otherwise as a text.POST /leads/:id/thanksand/thanks/skip, MCPsend_thanksandskip_thanks, and terminalrandRon the lead screen, which shows the draft first.contract/openapi.jsonis regenerated.referred,thanked,thanks_held,thanks_skipped). Activity output is escaped.AGENTS.mdentry.src/referral.test.tscovers validation, the draft's address and content, isolation from STOP and the cadence, nothing sent without approval, held texts, export, Activity, pages, the terminal, HTTP and MCP. I edited two existing tests,export.test.tsandserver.test.ts, because the CSV gained three columns and MCP gained two tools.What I didn't do
needsview; it appears as a tag on the row.Messages sent onlyin Activity still meansreplyandfirst_replyonly.To try it Restart the samples, then open James O'Neill and approve the thank-you to Sarah. Or add a lead with source Referral on the desk.
🤖 Generated with Claude Code
Closes #86