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

Download every lead and its status as a spreadsheet the agent can open in Excel or import into their CRM #40

Merged opened this

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

Merged

GET /leads.csv now downloads every lead the person may list, and the desk has a quiet "Download leads (CSV)" link to it. The export, openapi, readme, security, server and search tests pass, and lint-design is clean.

Notes

shipped production is serving it deploy aba151a

opened this

GET /leads.csv now downloads every lead the person may list, and the desk has a quiet "Download leads (CSV)" link to it. The export, openapi, readme, security, server and search tests pass, and lint-design is clean. I did not run the full suite or bun x tsc --noEmit: the repo has no tsconfig.json, so tsc only prints its help.

  • What the download does: it answers text/csv; charset=utf-8 with Content-Disposition: attachment; filename="leads-YYYY-MM-DD.csv" and the security headers from src/http.ts. Anon gets the same 401 JSON as /leads. show and q narrow the rows the way the desk does, up to the same 500 rows.
  • Columns: the ten you listed, with ISO times and CRLF line endings. "Status" is open, qualified or lost, so new and contacted leads both read as open. "Minutes to first reply" is blank while the lead is still waiting.
  • Quoting: fields with commas, quotes or newlines are quoted per RFC 4180. Any field starting with =, +, -, @, tab or carriage return gets a leading '. A phone number beginning with + therefore gets the quote too, which is what the issue asks for.
  • Last message at: this is the later of the last sent message and the last reply the lead wrote back. Logged calls are not counted. The query is lastMessages() in src/leads.ts, so src/export.ts stays plain data in, string out.
  • OpenAPI: the route is in /openapi.json and contract/openapi.json is regenerated. To describe a non-JSON answer I added an optional media field to the route's API description, and src/openapi.ts now uses it; before, it always wrote application/json.
  • Desk and README: the link sits under the lead list, carries the current show and q, and has a small .export style in static/app.css. The README has a short "Taking your leads with you" section.
  • Tests in src/export.test.ts:
    • header and row count match the 12 sample leads;
    • a name with a comma, quote and newline round-trips;
    • the formula guard works;
    • anon is refused;
    • show and q narrow the rows;
    • the minutes, texts-allowed and last-message columns are right;
    • the desk link carries the view and search.

The existing view tabs on the desk write a bare & in their links. My new link escapes it as &; I left the old ones alone.

No contract cell changed and there are no new dependencies. To try it, open the desk in the preview and tap "Download leads (CSV)", or fetch /leads.csv?show=closed.

🤖 Generated with Claude Code

Closes #36

2 earlier comments · 1 event
commented

GET /leads.csv now downloads every lead the person may list, and the desk has a quiet "Download leads (CSV)" link to it. The export, openapi, readme, security, server and search tests pass, and lint-design is clean. I did not run the full suite or bun x tsc --noEmit: the repo has no tsconfig.json, so tsc only prints its help.

  • What the download does: it answers text/csv; charset=utf-8 with Content-Disposition: attachment; filename="leads-YYYY-MM-DD.csv" and the security headers from src/http.ts. Anon gets the same 401 JSON as /leads. show and q narrow the rows the way the desk does, up to the same 500 rows.
  • Columns: the ten you listed, with ISO times and CRLF line endings. "Status" is open, qualified or lost, so new and contacted leads both read as open. "Minutes to first reply" is blank while the lead is still waiting.
  • Quoting: fields with commas, quotes or newlines are quoted per RFC 4180. Any field starting with =, +, -, @, tab or carriage return gets a leading '. A phone number beginning with + therefore gets the quote too, which is what the issue asks for.
  • Last message at: this is the later of the last sent message and the last reply the lead wrote back. Logged calls are not counted. The query is lastMessages() in src/leads.ts, so src/export.ts stays plain data in, string out.
  • OpenAPI: the route is in /openapi.json and contract/openapi.json is regenerated. To describe a non-JSON answer I added an optional media field to the route's API description, and src/openapi.ts now uses it; before, it always wrote application/json.
  • Desk and README: the link sits under the lead list, carries the current show and q, and has a small .export style in static/app.css. The README has a short "Taking your leads with you" section.
  • Tests in src/export.test.ts:
    • header and row count match the 12 sample leads;
    • a name with a comma, quote and newline round-trips;
    • the formula guard works;
    • anon is refused;
    • show and q narrow the rows;
    • the minutes, texts-allowed and last-message columns are right;
    • the desk link carries the view and search.

The existing view tabs on the desk write a bare & in their links. My new link escapes it as &; I left the old ones alone.

No contract cell changed and there are no new dependencies. To try it, open the desk in the preview and tap "Download leads (CSV)", or fetch /leads.csv?show=closed.

🤖 Generated with Claude Code

Changes requested — before the latest push

Changes needed, all in one round:

  1. Both doors: the export exists only on the page and HTTP. Add it to src/tty.ts and as an MCP tool in src/mcp.ts. Both must gate through the same permit path as the page, and the README must say how to use each. Today the README only covers the desk link and GET /leads.csv.
  2. Contract: the new door has no row in src/contract.test.ts. Add one for anon (401) and user (200).
  3. Data corruption: prefixing an apostrophe to any value starting with + or - rewrites phone numbers like "+1 206..." in the file, so a CRM import gets wrong phones. Keep the guard for = @ tab and CR. For phone, either keep the plus when the rest is digits, spaces or dashes, or document the choice. Test that a normal international phone survives.
  4. "Every lead" is silently cut at limit 500. Export all matching leads, or say so in the README and the response.
  5. Add Cache-Control: no-store to the CSV response. It is private data.
  6. Tests: drop the vacuous lastMessages(db) instanceof Map assertion. Test lastMessages with a real sent message and a real inbound reply, and check which one wins.
commented

All six review points are addressed and pushed to the same branch. I ran the export, contract, terminal, server, openapi, readme, design, inbound, live and actions tests and they pass, and lint-design is clean. I did not run the whole suite or tsc, because the repo has no tsconfig.json.

  1. Doors: the export now lives in one action, exportLeads in src/actions.ts. It asks permit(who, "lead", "list"), validates q, and returns { name, csv, count }. GET /leads.csv, the new MCP tool export_leads and x on the terminal desk all call it. The README now covers all three, plus the desk link.
  2. Contract: the lead.list row in src/contract.test.ts now also calls exportLeads and asserts it agrees with listLeads for every identity. anon is refused (401 over HTTP) and user is allowed (200). src/export.test.ts also checks the 401 and 200 over HTTP and the MCP tool as the caller.
  3. Phones: field(value, phone) keeps a phone-shaped value in the phone column as typed, so +1 206-555-0101 is not rewritten. The shape is a plus followed only by digits, spaces and () . -. The guard still applies to =, @, -, tab and CR everywhere, to a leading + in any other column, and to a malformed phone such as +1+cmd|…. The new tests cover both cases.
  4. Cap: the 500 limit is gone. The export reads all matching leads, and a test exports 520. The README says there is no cap.
  5. Caching: the CSV response now sends Cache-Control: no-store, and a test checks it.
  6. lastMessages test: I removed the instanceof Map assertion. The new test uses real sent messages and inbound replies on three leads: one where the send is later, one where the reply is later, and one with neither. It checks the later of the two wins and that the quiet lead has no entry.

Terminal limit: the terminal cannot write a file or hand over a download, since it may not write outside FORGE_APP_DATA. x therefore shows the CSV on screen for the current view and search, with control characters cleaned, and says the same file downloads from /leads.csv. If you want the terminal to write the file under FORGE_APP_DATA, that is a follow-up.

No contract cell changed.

🤖 Generated with Claude Code

commented

I merged main into the branch, resolved the three conflicts, and pushed it as 6419e38.

Each conflict was two independent additions, so I kept both:

  • src/actions.ts: the lastMessages import from this branch and the updateContact import from main.
  • src/contract.test.ts: the exportLeads import and the editLead import.
  • src/terminal.ts: this branch's exportScreen and main's mayEdit helper, both kept in full.

contract/openapi.json was regenerated after the merge. I ran the export, contract, terminal, server, openapi, readme, design, actions, details, db, live and inbound tests, and all pass. lint-design is clean. I did not run the whole suite; the forge's check does that on this push.

The CSV export behaves as in the last round.

🤖 Generated with Claude Code

Approved

All six earlier asks are met. The export is one action (exportLeads) behind permit(lead, list), and the page, /leads.csv, the MCP tool export_leads and x in the terminal all call it. The lead.list row in contract.test.ts checks it for every identity. The 500 cap is gone and a test exports 520. The response is no-store. Phone numbers like +1 206-555-0101 are kept as typed, while the formula guard still applies to a malformed + phone and to every other column. The lastMessages test uses real data. No contract cell is loosened, there are no new dependencies, and the README covers all three doors. The preview answers 401 to an unsigned request at /leads.csv, as the issue asks. I could not diff against bd8e932e4440 because the clone does not have that commit, so I read the final change as a whole. I did not fetch the preview signed in.

Non-blocking: the old view-tab links on the desk still write a bare &, unlike the new link.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs