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

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

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.

Notes

shipped production is serving it deploy aba151a

opened this

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_email and referrer_phone (new migration, existing leads untouched). readReferrer in src/actions.ts checks them with the same limits as a lead's own details, reusing contactProblem. 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't referral is refused.
  • Where it can be entered: the desk form, POST /leads, the MCP add_lead tool, and the terminal add flow, which asks only after a referral source.
  • Thank-you draft: src/thanks.ts and a new referrer_thanks table hold one draft per lead, deliberately outside message. Because of that, the lead's STOP, response clock, cadence and readyFor never see it. It names only the lead's first name and carries nothing from the lead's message or the agent's note.
  • Approving: sendThanks and skipThanksFor go through the existing lead update cell, so there is no contract change. A text approved outside quiet hours is held and turn sends it at 8:00. It goes by email when the referrer gave one, otherwise as a text.
  • Doors: POST /leads/:id/thanks and /thanks/skip, MCP send_thanks and skip_thanks, and terminal r and R on the lead screen, which shows the draft first. contract/openapi.json is 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.md entry.
  • Tests: src/referral.test.ts covers 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.ts and server.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 needs view; it appears as a tag on the row.
  • Messages sent only in Activity still means reply and first_reply only.

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

1 earlier comment · 1 event
commented

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_email and referrer_phone (new migration, existing leads untouched). readReferrer in src/actions.ts checks them with the same limits as a lead's own details, reusing contactProblem. 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't referral is refused.
  • Where it can be entered: the desk form, POST /leads, the MCP add_lead tool, and the terminal add flow, which asks only after a referral source.
  • Thank-you draft: src/thanks.ts and a new referrer_thanks table hold one draft per lead, deliberately outside message. Because of that, the lead's STOP, response clock, cadence and readyFor never see it. It names only the lead's first name and carries nothing from the lead's message or the agent's note.
  • Approving: sendThanks and skipThanksFor go through the existing lead update cell, so there is no contract change. A text approved outside quiet hours is held and turn sends it at 8:00. It goes by email when the referrer gave one, otherwise as a text.
  • Doors: POST /leads/:id/thanks and /thanks/skip, MCP send_thanks and skip_thanks, and terminal r and R on the lead screen, which shows the draft first. contract/openapi.json is 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.md entry.
  • Tests: src/referral.test.ts covers 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.ts and server.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 needs view; it appears as a tag on the row.
  • Messages sent only in Activity still means reply and first_reply only.

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 requested — before the latest push

Changes needed (one round):

  1. 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 permit for 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.
  2. bun test is 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.
  3. bun x tsc --noEmit was 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.
  4. 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.
  5. A repeat arrival that merges into an existing lead silently drops the referrer. Return a clear note in the result, or an invalid error 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.

commented

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.

  1. Contract rows. src/contract.test.ts now acts as each identity on sendThanks and skipThanksFor, and on the MCP tools send_thanks and skip_thanks. Each must give the same answer as lead 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.
  2. live.test.ts. I ran the full suite three times on a clean checkout of origin/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.
  3. Type check. bun x tsc --noEmit can't run here: the repo has no tsconfig or typescript dependency, and bun x tsc fetches the wrong package. I installed TypeScript 5 and @types/bun in $TMPDIR (not in the repo) and checked src/ non-test files under strict settings. That gives 4 errors, in actions.ts and routes.ts. The same 4 appear on origin/main, so none come from this change. I did not check the test files.
  4. 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.
  5. Merge dropping the referrer. addLead now returns invalid when 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.
Approved

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.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs