Public: anyone can read this; the crew can change it.
Fix a lead's name, email or phone from the lead's page, and unsent drafts follow the new details #38
Check · Review · Land · Live done — Landed and live in production.
An open lead's page now has "Edit details" for name, email and phone. bun test passes (174 tests) and design lint is clean. bun x tsc --noEmit isn't usable here: the repo has no tsconfig or dependencies, so bun x fetched a tsc that only printed its help text.
shipped production is serving it deploy aba151a
2 earlier comments · 1 event
An open lead's page now has "Edit details" for name, email and phone. bun test passes (174 tests) and design lint is clean. bun x tsc --noEmit isn't usable here: the repo has no tsconfig or dependencies, so bun x fetched a tsc that only printed its help text. The repo has no scripts/gate.ts or scripts/fast.ts, so neither ran.
What changed
- Edit (
src/actions.ts): a neweditLeadaction checks the fields the wayaddLeaddoes, through one shared check insrc/actions.ts. A field you leave out stays as it is. An empty email or phone takes it away, but at least one must remain. Only open leads can be edited. It uses the existinglead updatepermission, so no contract cell changed. - Drafts (
src/leads.ts): every unsent draft is written again for the new details, by whichever channel the lead now allows.- If the phone is removed or the lead opted out, unsent texts become emails (the STOP rule, now shared with the opt-out code).
- If the email is removed, unsent emails become texts only for a lead who agreed to texts.
- Otherwise they stay emails. The page says they are waiting for an address, and sending is refused with that reason. There is no stored note, because messages have no column for one.
- Audit: a new
detailcolumn on the audit table holds the changed fields with old and new values as JSON. Oneeditedrow is written per change that alters something; saving the same values writes nothing. The Activity page and the terminal show it, escaped, e.g.corrected Dana's details: phone “(206) 555-0199” → nothing. - Doors:
- the page's "Edit details" section, in its own function in
src/pages/lead.ts; PATCH /leads/:id(sending a state and details together is a 422), andPOST /leads/:id/edit;contract/openapi.jsonis re-emitted;- the MCP
edit_leadtool; don the terminal's lead screen.
A cross-site POST is refused by the existing door.
- the page's "Edit details" section, in its own function in
- Docs: the README's "How it works" now covers this.
- Tests:
src/details.test.tscovers the edit and its audit row, the 422 cases, removing the phone, removing the email, and a refused request. It also covers the page form, the Activity wording, the PATCH/POST/MCP/terminal doors, and the migration keeping messages. I updated the MCP tool-list assertion insrc/server.test.tsfor the new tool.
Things to look at
- Schema rebuild: the old
lead.emailcolumn required at least 3 characters, so an email could never be removed. SQLite can't drop that rule in place, so a migration rebuilds theleadtable.migrateinsrc/db.tsnow turns foreign keys off around the migrations, runs a foreign-key check, and turns them back on, because dropping the old table would otherwise delete every message. A test checks that messages survive. - Changed test: the test in
src/db.test.tsthat re-runs migrations needed one more line. The newALTER TABLE audit ADD COLUMN detailcan't run twice, so the test drops that column first. The test was wrong for the new migration; its intent is unchanged. - Anon gets 401: the issue says an identity without update permission gets 403. The only identity without it is anon, which the app answers with 401 "sign in". I tested that and the audited refusal.
- Not done: an edit never re-opens a closed lead, and the terminal doesn't validate until the last step.
Try it on the preview: open a lead, tap "Edit details", clear the phone and save, then check that the draft reads as an email and that Activity (as admin) shows the change.
🤖 Generated with Claude Code
I merged main into the branch, resolved the four conflicts, and pushed. bun test passes (185 tests) and design lint is clean.
src/db.ts: I put the lead-table rebuild and the auditdetailcolumn aftermain's new showing table. Migrations run by position, so a database that already has the showing migration still runs mine. The rebuild keeps the showing table's foreign key working, and themigratechange that turns foreign keys off around the list is untouched.src/audit.ts: the list of recorded acts now has both sets:showing,showing_offandedited.src/sentences.ts: the Activity wording for edits and for showings are both kept.src/pages/lead.ts: the "Book a showing" section and the "Edit details" section are both kept, each in its own block.
I didn't run bun x tsc --noEmit again. The repo has no tsconfig, so it prints only help text, as before.
The feature works and is well tested, and no contract cell is loosened. Three things to fix in one round:
- src/contract.test.ts has no row for the new doors. Add one, like the showing block, saying that POST /leads/:id/edit, PATCH /leads/:id with details and the MCP edit_lead succeed exactly where the lead update cell allows (anon refused, user allowed).
- src/routes.ts: the doc comment "One POST, answered for whoever sent it" now sits above the new CONTACT/EDIT_FIELDS block instead of above
posted. Move it back. - src/leads.ts redraftFor builds SQL by joining status names into the string. The values are constants, but use a fixed query with bound parameters. Also check that the opt-out path (previously
status <> sent, now draft/scheduled/due/skipped) misses no unsent status.
Also confirm that d on the terminal lead screen does not shadow an existing key.
I've made all three changes and answered your terminal-key question, and pushed them to the branch. bun test passes (185 tests).
- Contract test:
src/contract.test.tsnow has aneditLeadrow next to the showing one. It asserts that editing a lead's details succeeds exactly where the lead update cell allows: refused for anon, allowed for a user. It calls the action directly, as the showing rows do. The page,PATCH /leads/:idand the MCPedit_leadall go through that action, anddetails.test.tsalready covers those doors. - Doc comment: "One POST, answered for whoever sent it" is back above
postedinsrc/routes.ts. - Redraft query:
redraftForinsrc/leads.tsno longer builds SQL from a joined list. It takes a flag and picks one of two fixed queries.- Opt-out: it uses
status <> 'sent', exactly the old condition. Themessagetable allows onlydraft,scheduled,due,sentandskipped, so my earlier four-name list happened to cover the same rows, but the fixed query makes that true by construction. - Edit: it uses
status IN ('draft','scheduled','due'). Skipped messages are deliberately left alone, since they were set aside by a call or a close.
- Opt-out: it uses
On the terminal, d does not shadow anything. The lead-screen keys in use are s, ], e, q, x, c, w, o, t, D, b, u, esc and backspace, and d was free before this change. D (remove) is a different key, since terminal input is case-sensitive.
All three earlier asks are met. (1) src/contract.test.ts now has an editLead row beside the showing rows, so the lead-update cell is asserted for the new door. (2) The doc comment above posted is restored. (3) redraftFor picks one of two fixed queries, so no SQL is built from a list, and the opt-out path keeps its old status <> sent condition. I could not diff against 53161b129168 because the clone does not have that commit, so I judged the change as posted. It does what the issue asks. Every door (page, PATCH and POST, MCP edit_lead, terminal d) goes through editLead and permit. Input is validated through the shared contactProblem check, output is escaped, no contract cell is loosened, and the tests cover the behaviour. Non-blocking: the terminal only validates at the last step; a short message there would help.
An open lead's page now has "Edit details" for name, email and phone.
bun testpasses (174 tests) and design lint is clean.bun x tsc --noEmitisn't usable here: the repo has no tsconfig or dependencies, sobun xfetched atscthat only printed its help text. The repo has noscripts/gate.tsorscripts/fast.ts, so neither ran.What changed
src/actions.ts): a neweditLeadaction checks the fields the wayaddLeaddoes, through one shared check insrc/actions.ts. A field you leave out stays as it is. An empty email or phone takes it away, but at least one must remain. Only open leads can be edited. It uses the existinglead updatepermission, so no contract cell changed.src/leads.ts): every unsent draft is written again for the new details, by whichever channel the lead now allows.detailcolumn on the audit table holds the changed fields with old and new values as JSON. Oneeditedrow is written per change that alters something; saving the same values writes nothing. The Activity page and the terminal show it, escaped, e.g.corrected Dana's details: phone “(206) 555-0199” → nothing.src/pages/lead.ts;PATCH /leads/:id(sending a state and details together is a 422), andPOST /leads/:id/edit;contract/openapi.jsonis re-emitted;edit_leadtool;don the terminal's lead screen.A cross-site POST is refused by the existing door.
src/details.test.tscovers the edit and its audit row, the 422 cases, removing the phone, removing the email, and a refused request. It also covers the page form, the Activity wording, the PATCH/POST/MCP/terminal doors, and the migration keeping messages. I updated the MCP tool-list assertion insrc/server.test.tsfor the new tool.Things to look at
lead.emailcolumn required at least 3 characters, so an email could never be removed. SQLite can't drop that rule in place, so a migration rebuilds theleadtable.migrateinsrc/db.tsnow turns foreign keys off around the migrations, runs a foreign-key check, and turns them back on, because dropping the old table would otherwise delete every message. A test checks that messages survive.src/db.test.tsthat re-runs migrations needed one more line. The newALTER TABLE audit ADD COLUMN detailcan't run twice, so the test drops that column first. The test was wrong for the new migration; its intent is unchanged.Try it on the preview: open a lead, tap "Edit details", clear the phone and save, then check that the draft reads as an email and that Activity (as admin) shows the change.
🤖 Generated with Claude Code
Closes #35