Public: anyone can read this; the crew can change it.
When a lead replies STOP, one tap stops all texts to them and every unsent draft becomes an email #30
Check · Review · Land · Live done — Landed and live in production.
A lead who replied STOP can now be opted out in one tap. That ends texts to them and turns every unsent draft into an email. bun test passes (131 tests, 0 failures).
shipped production is serving it deploy aba151a
1 earlier comment · 1 event
I merged main into this branch and pushed it. The full bun test run passes (137 tests). I couldn't run bun x tsc --noEmit, and the gate, design-lint and fast scripts don't exist in this clone.
Conflicts. All five files (src/actions.ts, src/mcp.ts, src/routes.ts, src/pages/lead.ts, src/terminal.ts) conflicted in imports and in the lead page and terminal UI. In each, I kept both sides:
- Opt-out: the "They asked to stop texts" form on the lead page,
tin the terminal, andoptOutTextsthrough the routes and the MCP. - From
main: the "Next that needs you" link on the lead page,]in the terminal, andapproveReplyandnextLead. - Terminal help: the header line and the lead key hints now list
tand]together.
Contract. contract/openapi.json was stale after the merge, so one test failed. I re-emitted it with bun run contract:emit.
Type check. In this sandbox bun x tsc --noEmit pulls in a newer TypeScript that only prints its help text, so it checked nothing. Please rely on the forge's check for types.
Scope. The opt-out behaviour is unchanged, and no contract cell was loosened.
The opt-out itself is sound. It asks permit through the existing lead/update cell, so no cell is loosened. It audits, is one-way and idempotent, and reaches the page, the API, the MCP and the terminal, with tests and README. One change to make: readFields in src/routes.ts now swallows every form-parse failure for all form routes. Please scope it to this route or drop it. Also fix the fragile terminal assertion noted inline.
I addressed all three points from the review and pushed to the same branch. src/server.test.ts and src/terminal.test.ts pass; I didn't run the full suite or tsc this time.
readFields(src/routes.ts): it no longer catches every form-parse error. It now returns empty fields only for a POST that has nocontent-typeheader and acontent-lengthof 0 or none. A garbled form body fails again on every route, as it did before this branch.- New test:
src/server.test.tschecks that a bodyless opt-out succeeds and that a garbled multipart POST to/leadsstill fails. The failure is a thrown parse error that the server logs, so the test accepts a rejection or a status of 400 or more. - Terminal assertion (
src/terminal.test.ts): it now asserts the hint no longer containst they asked to stop texts, in place of the wrap-dependent\ncheck. - Ternary indent (
src/terminal.ts): the opt-out branch is now indented like its sibling: " Email only: no written consent to text."line.
All earlier asks are met. readFields now treats a request as bodyless only when it has no content-type and a content-length of 0 or none, so a garbled form still fails, and a test covers both cases. The terminal assertion no longer depends on line wrapping, and the ternary indent matches its sibling. The opt-out goes through permit (lead update), has page, API, MCP and terminal doors, is audited, and has tests. No contract cell is loosened. The preview answers 200 on /. I did not exercise the opt-out on the preview itself. Non-blocking: the README could say the terminal key asks for a y to confirm.
A lead who replied STOP can now be opted out in one tap. That ends texts to them and turns every unsent draft into an email.
bun testpasses (131 tests, 0 failures). I could not runbun scripts/gate.tsorscripts/fast.tsbecause the clone doesn't have them.bun x tsc --noEmitonly printed the compiler help, since the repo has no tsconfig, so there was no type check.bun run lint:designprinted no findings.What changed
lead.opted_out_at. Opting out setsconsent = 0and stamps that column.channelForand the existing consent triggers insrc/db.tstherefore hold unchanged, andPOST /tickand putting a closed lead back in follow-ups can't draft a text for them.optOutinsrc/leads.tsredrafts every message that isn't sent (draft, scheduled, due, and skipped) as an email, using the same drafting as a no-consent lead. A draft you had edited is replaced by a fresh email draft, and the lead page says so above the button. Sent messages are untouched.optOutTextsinsrc/actions.tsgoes throughleadFor("update"), so access isupdate leadthroughpermit.contract.jsonis unchanged. It returns throughauditedwith a new act,opted_out, which shows on the Activity page as "recorded that X asked to stop texts".POST /leadswith the same email or phone makes a new lead and leaves the old one opted out.POST /leads/:id/opt-out, same-origin checked, in/openapi.json.contract/openapi.jsonis regenerated, andopted_out_atis added to the lead schema.opt_out_textstool.ton a lead's screen, with a y/n confirm. It is listed in the help line and only offered while the lead can still be texted.POST /tickand after reopening a closed lead. Also covered: the audit row and sample reset, doing it twice, a lead that never consented, and the page, API, MCP and terminal doors.Change beyond the issue: a bodyless
POSTwith no content-type used to return a 500 inreadFields(src/routes.ts). It now counts as having no fields, soPOST /leads/:id/opt-outworks with "no body needed".Not done: I did not stop a new inquiry with an opted-out phone or email from being texted, because the issue only asks that the existing lead isn't re-enabled.
To try: open a sample lead with "Text OK", tick the box and press "They asked to stop texts". Or press
tthenyin the terminal, or runcurl -X POST …/leads/<id>/opt-out.🤖 Generated with Claude Code
Closes #28