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
Check · Review · Land · Live done — Landed and live in production.
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.
shipped production is serving it deploy aba151a
1 earlier comment · 1 event
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,sourceandemailand/orphoneare required;message,state(orstatus) andarrived atare 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/importLeadsinsrc/actions.ts: they askpermitfor lead create and mark each row as new, duplicate or refused with the reason. Duplicates use the same email-or-phone rule asaddLead, and also catch a repeat within the file.importLeadsre-reads the file rather than trusting the preview. Each lead gets an audit row with the new actimported, and a refused or empty attempt is audited too.- Imported leads are history, not inquiries, via a new
importedcolumn (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 tocontract.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 inqualifiedorlostis 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
- Sign in and open "Import leads (CSV)" from the desk.
- Upload a file from "Download leads (CSV)" and check the preview.
- Press Import. The desk shows the new leads with no clock and no drafts.
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.
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:
Ion 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.yimports and esc cancels. It goes throughpreviewImportandimportLeads, so the same lead-createpermitcell applies. A guest's import is refused, and the desk is unchanged.importLeadsalready emitslead.added, so web viewers update live. - MCP: new
preview_importandimport_leadstools, each takingcsv.contract.test.tsnow exercises both tools as every identity, andserver.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_SCHEMAis 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. 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.
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 exceptlive.test.ts("a write from another process…"), which fails the same way on an untouchedmaincheckout in this sandbox.bun x tsc --noEmitcould not check anything: the repo has notsconfig.jsonor dependencies, sotsconly printed its help.scripts/gate.tsdoes not exist, andbun run lint:designprinted nothing.What changed
src/import.ts(new): reads RFC 4180 CSV and finds columns by header, any case.name,sourceandemailand/orphoneare required;message,state(orstatus) andarrived atare 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/importLeadsinsrc/actions.ts: they askpermitfor lead create and mark each row as new, duplicate or refused with the reason. Duplicates use the same email-or-phone rule asaddLead, and also catch a repeat within the file.importLeadsre-reads the file rather than trusting the preview. Each lead gets an audit row with the new actimported, and a refused or empty attempt is audited too.importedcolumn (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.-
GET /leads/importis the page, with a file upload or a paste box. -POST /leads/import/previewwrites nothing. -POST /leads/importdoes 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.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 tocontract.test.ts. The README has a "Bringing your leads in" paragraph.What I chose not to do
new. A lead that comes inqualifiedorlostis not counted as qualified or lost in the week report.How to try it
Closes #102