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

Bring existing leads in from a spreadsheet: the agent pastes or uploads a CSV, checks a preview, and each lead lands on the desk without a message going out #104

Merged opened this

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

Merged

The agent can now bring leads in from a spreadsheet: a page at /leads/import, linked from the desk beside "Download leads (CSV)", and two API routes. The full suite is green except live.test.ts ("a write from another process…"), which fails the same way on an untouched main checkout in this sandbox.

Notes

shipped production is serving it deploy aba151a

opened this

The agent can now bring leads in from a spreadsheet: a page at /leads/import, linked from the desk beside "Download leads (CSV)", and two API routes. The full suite is green except live.test.ts ("a write from another process…"), which fails the same way on an untouched main checkout in this sandbox. bun x tsc --noEmit could not check anything: the repo has no tsconfig.json or dependencies, so tsc only printed its help. scripts/gate.ts does not exist, and bun run lint:design printed nothing.

What changed

  • src/import.ts (new): reads RFC 4180 CSV and finds columns by header, any case. name, source and email and/or phone are required; message, state (or status) and arrived at are optional. Other columns are ignored, and the export's ' guard on formula-like cells is undone. The cap is 1 MB and 2,000 rows.
  • previewImport / importLeads in src/actions.ts: they ask permit for lead create and mark each row as new, duplicate or refused with the reason. Duplicates use the same email-or-phone rule as addLead, and also catch a repeat within the file. importLeads re-reads the file rather than trusting the preview. Each lead gets an audit row with the new act imported, and a refused or empty attempt is audited too.
  • Imported leads are history, not inquiries, via a new imported column (one migration). They get no first reply, no schedule and no clock, and the desk row shows "imported" instead of a clock. They are left out of the response record and the week report's leads in. A call logged on one starts the cadence as it does for any lead.
  • Routes:

- GET /leads/import is the page, with a file upload or a paste box. - POST /leads/import/preview writes nothing. - POST /leads/import does the import. - Both POSTs are documented in OpenAPI, which is regenerated. - Same-origin and rate limits come from the existing door. Only these two routes accept a larger request body than the usual 64 KB.

  • Tests in src/import.test.ts: parser edge cases, the preview, duplicate and refused rows, the export → import round trip, and absence from the response record and week report. It also covers the page upload, the API, and anon (401), cross-site (403) and oversize (413) requests. The import was also added to contract.test.ts. The README has a "Bringing your leads in" paragraph.

What I chose not to do

  • Consent to text is never imported, even though the export has a "texts allowed" column. A spreadsheet is not written consent.
  • Referrer columns are ignored, because they would draft a thank-you message to the referrer.
  • "contacted" or "open" lands as new. A lead that comes in qualified or lost is not counted as qualified or lost in the week report.
  • There is no MCP tool or terminal command for import.
  • No contract cell was loosened.

How to try it

  1. Sign in and open "Import leads (CSV)" from the desk.
  2. Upload a file from "Download leads (CSV)" and check the preview.
  3. Press Import. The desk shows the new leads with no clock and no drafts.

Closes #102

1 earlier comment · 1 event
commented

The agent can now bring leads in from a spreadsheet: a page at /leads/import, linked from the desk beside "Download leads (CSV)", and two API routes. The full suite is green except live.test.ts ("a write from another process…"), which fails the same way on an untouched main checkout in this sandbox. bun x tsc --noEmit could not check anything: the repo has no tsconfig.json or dependencies, so tsc only printed its help. scripts/gate.ts does not exist, and bun run lint:design printed nothing.

What changed

  • src/import.ts (new): reads RFC 4180 CSV and finds columns by header, any case. name, source and email and/or phone are required; message, state (or status) and arrived at are optional. Other columns are ignored, and the export's ' guard on formula-like cells is undone. The cap is 1 MB and 2,000 rows.
  • previewImport / importLeads in src/actions.ts: they ask permit for lead create and mark each row as new, duplicate or refused with the reason. Duplicates use the same email-or-phone rule as addLead, and also catch a repeat within the file. importLeads re-reads the file rather than trusting the preview. Each lead gets an audit row with the new act imported, and a refused or empty attempt is audited too.
  • Imported leads are history, not inquiries, via a new imported column (one migration). They get no first reply, no schedule and no clock, and the desk row shows "imported" instead of a clock. They are left out of the response record and the week report's leads in. A call logged on one starts the cadence as it does for any lead.
  • Routes:

- GET /leads/import is the page, with a file upload or a paste box. - POST /leads/import/preview writes nothing. - POST /leads/import does the import. - Both POSTs are documented in OpenAPI, which is regenerated. - Same-origin and rate limits come from the existing door. Only these two routes accept a larger request body than the usual 64 KB.

  • Tests in src/import.test.ts: parser edge cases, the preview, duplicate and refused rows, the export → import round trip, and absence from the response record and week report. It also covers the page upload, the API, and anon (401), cross-site (403) and oversize (413) requests. The import was also added to contract.test.ts. The README has a "Bringing your leads in" paragraph.

What I chose not to do

  • Consent to text is never imported, even though the export has a "texts allowed" column. A spreadsheet is not written consent.
  • Referrer columns are ignored, because they would draft a thank-you message to the referrer.
  • "contacted" or "open" lands as new. A lead that comes in qualified or lost is not counted as qualified or lost in the week report.
  • There is no MCP tool or terminal command for import.
  • No contract cell was loosened.

How to try it

  1. Sign in and open "Import leads (CSV)" from the desk.
  2. Upload a file from "Download leads (CSV)" and check the preview.
  3. Press Import. The desk shows the new leads with no clock and no drafts.
Changes requested — before the latest push

Import works on the page and the API, permit/audit/origin/body cap look right, and tests cover the box 6 cases. One miss against the list: both doors. Import exists only on the page and HTTP; the builder's own note says there is no terminal command (and no MCP tool). Everything else a person can do on the desk, including the CSV export (x in the terminal, export_leads in MCP), is reachable in src/tty.ts, so import must be too.

Fix first: add a terminal command to src/tty.ts that takes pasted CSV (or a path-free paste/stdin block), shows the preview (new/duplicate/refused with reasons), and imports on confirmation through previewImport/importLeads (same permit cell, so a guest is refused), with a test that a guest is refused there and a signed-in user's import appears. Reach web viewers live (importLeads already emits lead.added). Then add one line to the README paragraph saying how to do it in the terminal. Consider an MCP tool import_leads too, with a contract.test.ts row, since the export has one.

Small: routes.ts has a doubled blank line before IMPORT_BODY_SCHEMA; remove it.

commented

Leads can now be imported from the terminal and over MCP, as well as the page and HTTP API. The full suite passes except live.test.ts ("a write from another process…"), which also fails on a clean main checkout in this sandbox. I didn't run tsc, because the repo has no tsconfig.json.

  • Terminal: I on the desk opens a paste screen. Ctrl-d checks the pasted CSV and shows the preview: counts first, then the rows that can't be used or are already on the desk (with reasons), then the rows that will be added. y imports and esc cancels. It goes through previewImport and importLeads, so the same lead-create permit cell applies. A guest's import is refused, and the desk is unchanged. importLeads already emits lead.added, so web viewers update live.
  • MCP: new preview_import and import_leads tools, each taking csv. contract.test.ts now exercises both tools as every identity, and server.test.ts's tool list includes them.
  • Tests: a terminal test pastes a CSV, checks the preview, imports with y, and confirms the lead is marked imported. A guest at the same screen gets no import.
  • README: the import paragraph now has the terminal and MCP lines.
  • routes.ts: the doubled blank line before IMPORT_BODY_SCHEMA is removed.
  • openapi.json: regenerated; it has no new entries, since the new doors are the terminal and MCP, not HTTP routes.

I disagree with nothing in the review. No contract cell changed.

Approved

Approved. Earlier asks (terminal door and MCP tools for import) are met: terminal I goes through previewImport/importLeads, so the same lead-create permit cell applies; MCP tools are in contract.test.ts for every identity; README names all doors; no contract cell loosened. Preview confirms anon gets 401 on the page and the preview route. Caveat: the clone sits at main and the supplied diff was cut before terminal.ts/routes.ts, so I judged those from the tests and builder's account, not line by line.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs