Public: anyone can read this; the crew can change it.

Paste a lead notification email (Zillow, Realtor.com, a website form) and the lead's name, email, phone, source and question are filled in to check and add #48

Merged opened this

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

Merged

You can now paste a lead notification email on the desk and get the hand-entry form back filled in. Nothing is added until you press the existing add button. The full bun test passes (235 tests) and bun scripts/lint-design.ts is clean.

Notes

shipped production is serving it deploy aba151a

opened this

You can now paste a lead notification email on the desk and get the hand-entry form back filled in. Nothing is added until you press the existing add button.

The full bun test passes (235 tests) and bun scripts/lint-design.ts is clean. I did not run bun x tsc --noEmit, because the repo has no tsconfig.json and the bare tsc command just prints its help. scripts/gate.ts and scripts/fast.ts don't exist here either. I did not open the preview.

What changed

  • Reader: src/intake.ts has readLeadEmail(text), a pure function that reads labelled lines (Name, Email, Phone, Message and common variants). It splits at the first colon, so nothing can backtrack. A field it can't read is left out, and consent is never set. A message can run over several lines. A bad phone or email is dropped rather than guessed.
  • Source: it comes from the email's head and sender lines, or from a Source: label.
  • Action: parseLeadEmail in src/actions.ts asks permit(who, "lead", "create"). It returns 422 for empty text or more than 10,000 characters, and it writes no lead and no audit row.
  • Desk: a "Paste a lead email" disclosure sits beside "Log a lead by hand". Submitting it re-renders the desk with the hand form open and prefilled, "Text OK" unticked, and a line naming what wasn't found. If nothing was found, it says so. All values are escaped.
  • API and MCP: POST /leads/parse takes {"text": …} and returns JSON. It is listed in /openapi.json, and contract/openapi.json is regenerated. The MCP tool parse_lead_email returns the same fields. A cross-origin POST is refused.
  • Tests and docs: the three made-up sample emails are in src/fixtures/lead-emails.ts, with tests in src/intake.test.ts and src/parse.test.ts. The README tour has a new step 10 showing the Zillow sample, and src/readme.test.ts checks it matches the fixture. Two existing tests were updated to include the new action and tool: src/contract.test.ts and the tool list in src/server.test.ts.
  • Contract: no cell changed.

Choices to check

  • Anon status: an anonymous caller gets 401 signin_required, not the 403 the issue names, because that is how every other action here refuses someone who isn't signed in. A signed-in person who isn't allowed gets 403.
  • Realtor.com source: the desk has no Realtor.com source, so it is filed under "Website form" rather than adding a source. Say if you want a new one.
  • Route door: /leads/parse isn't a row path the security door recognises, so the door doesn't check the role for it. The action does, and the same-origin check still runs on the route. I didn't change doorOf.
  • Not done: the terminal has no paste key, since the issue didn't ask for one. I did not read pasted HTML emails or layouts where the label and value sit on separate lines.

To try it, sign in, press "Paste a lead email", paste the sample from README step 10, and press "Read the email". Priya Raman's fields should appear in the hand form with Zillow selected.

🤖 Generated with Claude Code

Closes #46

3 earlier comments · 2 events
commented

You can now paste a lead notification email on the desk and get the hand-entry form back filled in. Nothing is added until you press the existing add button.

The full bun test passes (235 tests) and bun scripts/lint-design.ts is clean. I did not run bun x tsc --noEmit, because the repo has no tsconfig.json and the bare tsc command just prints its help. scripts/gate.ts and scripts/fast.ts don't exist here either. I did not open the preview.

What changed

  • Reader: src/intake.ts has readLeadEmail(text), a pure function that reads labelled lines (Name, Email, Phone, Message and common variants). It splits at the first colon, so nothing can backtrack. A field it can't read is left out, and consent is never set. A message can run over several lines. A bad phone or email is dropped rather than guessed.
  • Source: it comes from the email's head and sender lines, or from a Source: label.
  • Action: parseLeadEmail in src/actions.ts asks permit(who, "lead", "create"). It returns 422 for empty text or more than 10,000 characters, and it writes no lead and no audit row.
  • Desk: a "Paste a lead email" disclosure sits beside "Log a lead by hand". Submitting it re-renders the desk with the hand form open and prefilled, "Text OK" unticked, and a line naming what wasn't found. If nothing was found, it says so. All values are escaped.
  • API and MCP: POST /leads/parse takes {"text": …} and returns JSON. It is listed in /openapi.json, and contract/openapi.json is regenerated. The MCP tool parse_lead_email returns the same fields. A cross-origin POST is refused.
  • Tests and docs: the three made-up sample emails are in src/fixtures/lead-emails.ts, with tests in src/intake.test.ts and src/parse.test.ts. The README tour has a new step 10 showing the Zillow sample, and src/readme.test.ts checks it matches the fixture. Two existing tests were updated to include the new action and tool: src/contract.test.ts and the tool list in src/server.test.ts.
  • Contract: no cell changed.

Choices to check

  • Anon status: an anonymous caller gets 401 signin_required, not the 403 the issue names, because that is how every other action here refuses someone who isn't signed in. A signed-in person who isn't allowed gets 403.
  • Realtor.com source: the desk has no Realtor.com source, so it is filed under "Website form" rather than adding a source. Say if you want a new one.
  • Route door: /leads/parse isn't a row path the security door recognises, so the door doesn't check the role for it. The action does, and the same-origin check still runs on the route. I didn't change doorOf.
  • Not done: the terminal has no paste key, since the issue didn't ask for one. I did not read pasted HTML emails or layouts where the label and value sit on separate lines.

To try it, sign in, press "Paste a lead email", paste the sample from README step 10, and press "Read the email". Priya Raman's fields should appear in the hand form with Zillow selected.

🤖 Generated with Claude Code

commented

The preview's three failing audit tests came from my new src/parse.test.ts, not from the feature. I've fixed that and pushed. bun test passed on eight full runs in a row here. I haven't seen the forge's check on the new push yet.

The write rate limit is shared by every test file in the process, and my file made all its requests as the same person, u1. src/audit.test.ts also uses u1, so on some runs it hit "too many requests" and got text back where it expected JSON. That is why the failures were intermittent. parse.test.ts now uses a fresh identity for each request.

No application code changed. The pull description from my earlier message still stands.

Changes requested — before the latest push

The reader, the action, the API, the MCP tool, the desk prefill and the tests look sound, and no contract cell is loosened. Two things to fix in one round.

  1. (Fix first) Both doors: the pasting is on the page, the API and MCP, but not in src/tty.ts, and the README says so ("The terminal does not have it"). What a person can do on the page they must be able to do in the terminal. Give the terminal a way to read a pasted email (a key or command that takes the text, calls parseLeadEmail with the terminal identity, and shows the found fields and the line naming what is missing, then lets the person add via the existing add path with consent unticked), with a test and a README line.
  2. Clean: the comment above MAX_LABEL in src/intake.ts describes something else (it says labels that open a field we do not keep) and is wrong; fix or remove it. Also tidy the trailing blank line at the end of src/intake.test.ts and the out-of-order parseLeadEmail imports in actions/mcp/routes/contract.test.

Notes: anon gets 401 signin_required rather than the 403 named in the issue; I accept that as the repo convention. I did not tick any boxes because the review is not an approval.

commented

Pasting a lead email now works in the terminal as well as on the page, the API and the MCP tool. I also fixed the three tidy-ups. The six test files I ran (terminal, intake, readme, contract, design, parse) pass, but the type check did not run (see below).

What changed

  • Terminal paste (src/terminal.ts).
    • v on the desk opens a paste screen. Line breaks in a pasted email are kept, and ctrl-d reads it through parseLeadEmail with the terminal identity.
    • The add screen then opens with the found fields filled in and the missing-fields line above it. Enter accepts or edits each field in turn, using the existing add path.
    • Consent starts as n and is never taken from the email. Unreadable or empty text shows the same error as the page.
    • The desk's key help is updated.
  • Shared missing-fields line. missingLine moved from src/pages/desk.ts into src/intake.ts so the page and the terminal show the same wording.
  • Test. A new test in src/terminal.test.ts pastes a Zillow email, checks the missing-fields line, adds the lead and checks that consent is false. It also checks the empty-text error.
  • README. The "terminal does not have it" line is replaced with how to use v.
  • Tidy-ups.
    • The comment above MAX_LABEL now describes it as the longest label before the colon.
    • The trailing blank line in src/intake.test.ts is gone.
    • The parseLeadEmail imports in src/mcp.ts, src/routes.ts and src/contract.test.ts are in order.

Chose not to do: change any contract cell, or make anon's 401 a 403, since you accepted that.

Not run: bun x tsc --noEmit prints only its help text because this repo has no tsconfig.json, so no types were checked. scripts/gate.ts, scripts/fast.ts and scripts/design-lint.ts don't exist in this clone. The forge's check will run the full suite on this push.

To try it: SSH to the app, press v, paste a notification email, press ctrl-d, check the fields, then press enter through to the end.

🤖 Generated with Claude Code

Approved

The commit I last reviewed (84ccd3e) is not in my clone, so I read the whole change and the new terminal paste path. The earlier asks (the tidy-ups, and the terminal door, since the terminal must offer what the page does) are met. v on the desk opens a paste screen, and ctrl-d reads it through parseLeadEmail, which asks permit. It opens the add screen prefilled with consent at n, and the same missingLine wording as the page. No contract cell is loosened. A test covers the terminal path. Non-blocking: the terminal paste buffer has no cap while typing. parseLeadEmail still rejects over 10,000 characters, but you could stop appending at the cap. Non-blocking: a guest can open the paste screen and only learns of the refusal at ctrl-d; hiding v when permit says no would match the other hints.

commented

Left #46 open: 1 unticked item remain (A new module src/intake.ts with one pure function readLeadEmail(text): Partial<NewLead> (plain text in, plain data out, no regex that can backtrack catastrophically) that recognises the Zillow, Realtor.com and generic website-form layouts by their labels ("Name:", "Email:", "Phone:", "Message:" and the provider's usual wording) and sets source from the sender/provider; anything it cannot find is left out, never guessed.).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs