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

The agent downloads all their deals as one file (dates, parties, notes, moves and every approved message) from the Profile page, so leaving the app never means losing a deal #172

Merged opened this

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

Merged

Profile now has a Download all my deals link to GET /deals/export.json, which saves every deal the signed-in person may read as one JSON file. I ran the new tests plus the openapi, contract, profile, design, a11y, speed, security, server and terminal suites. All pass.

Notes

shipped production is serving it deploy d2eada7

opened this

Profile now has a Download all my deals link to GET /deals/export.json, which saves every deal the signed-in person may read as one JSON file.

I ran the new tests plus the openapi, contract, profile, design, a11y, speed, security, server and terminal suites. All pass. I did not run the full bun test; the forge does that on push. There is no scripts/gate.ts or scripts/fast.ts in this repo, and bun x tsc --noEmit only printed tsc's help because there is no tsconfig, so I did not type-check.

What changed

  • src/export.ts (new): it turns the deal views into plain data, { version: 1, exported_at, truncated, deals: [...] }. It reads the same listDeals result the deal page uses, so contacts are blanked exactly as the deal page blanks them. Nothing is invented, and the audit log is never in it.
  • Each deal carries:

- Its address, side, figures and closing time and place. - Its state: open, closed or fell_through, with the reason. - Its parties, with phone and email. - Each date with due, done, waived, owed_by, note and moves (from, to, reason, by, at). - Each sent message with its exact approved subject and body.

  • Doors: the page route sends application/json, attachment; filename="deal-clock-YYYY-MM-DD.json", no-store and the security headers. GET /api/deals/export answers the same JSON and is described in /openapi.json. MCP has an export_deals tool. A stranger gets a 401 at all three. No cell of contract.json is loosened.
  • Docs: one short README paragraph under "Make it yours", and the format in docs/TECHNICAL.md.
  • Tests: src/export.test.ts checks that the listed fields are present, the headers, the 401, MCP, and the cap. A 200+ deal export answers in under 200 ms. src/server.test.ts now expects export_deals in its list of MCP tools.

What I chose

  • Cap: I bounded the work at 2000 deals per file, with truncated: true past that.
  • Private deal not tested end to end: I did not write the test that a deal opened by someone else and private to them is absent. In the current contract.json every signed-in user may list every deal, so no such deal exists. The export relies on listDeals, which already applies permit, so it narrows the moment the table does.
  • Left out: declined and held reminders are not exported, since the issue asks for sent messages only.

To try it: open /profile in the preview and click the link, or fetch /api/deals/export.

🤖 Generated with Claude Code

Closes #164

1 earlier comment · 1 event
commented

Profile now has a Download all my deals link to GET /deals/export.json, which saves every deal the signed-in person may read as one JSON file.

I ran the new tests plus the openapi, contract, profile, design, a11y, speed, security, server and terminal suites. All pass. I did not run the full bun test; the forge does that on push. There is no scripts/gate.ts or scripts/fast.ts in this repo, and bun x tsc --noEmit only printed tsc's help because there is no tsconfig, so I did not type-check.

What changed

  • src/export.ts (new): it turns the deal views into plain data, { version: 1, exported_at, truncated, deals: [...] }. It reads the same listDeals result the deal page uses, so contacts are blanked exactly as the deal page blanks them. Nothing is invented, and the audit log is never in it.
  • Each deal carries:

- Its address, side, figures and closing time and place. - Its state: open, closed or fell_through, with the reason. - Its parties, with phone and email. - Each date with due, done, waived, owed_by, note and moves (from, to, reason, by, at). - Each sent message with its exact approved subject and body.

  • Doors: the page route sends application/json, attachment; filename="deal-clock-YYYY-MM-DD.json", no-store and the security headers. GET /api/deals/export answers the same JSON and is described in /openapi.json. MCP has an export_deals tool. A stranger gets a 401 at all three. No cell of contract.json is loosened.
  • Docs: one short README paragraph under "Make it yours", and the format in docs/TECHNICAL.md.
  • Tests: src/export.test.ts checks that the listed fields are present, the headers, the 401, MCP, and the cap. A 200+ deal export answers in under 200 ms. src/server.test.ts now expects export_deals in its list of MCP tools.

What I chose

  • Cap: I bounded the work at 2000 deals per file, with truncated: true past that.
  • Private deal not tested end to end: I did not write the test that a deal opened by someone else and private to them is absent. In the current contract.json every signed-in user may list every deal, so no such deal exists. The export relies on listDeals, which already applies permit, so it narrows the moment the table does.
  • Left out: declined and held reminders are not exported, since the issue asks for sent messages only.

To try it: open /profile in the preview and click the link, or fetch /api/deals/export.

🤖 Generated with Claude Code

Changes requested — before the latest push

Two things to fix, plus tidying. No security finding: the export reads listDeals (which asks permit), no cell is loosened, strangers get 401, the audit log is absent.

  1. (First) The terminal has no way to export. The page, API and MCP have it, but src/tty.ts does not, and the review bar says anything a person does on the page they can do in the terminal, with the README saying how. Add an export command in src/tty.ts that gates on the same permit cell as the page and prints or writes the same JSON via exportDeals. Add a test for it, and one line in README/TECHNICAL.
  2. Box 4 asks for a test that a deal private to someone else is absent. It is missing, and the PR description admits it. The contract currently lets every user list every deal, so do it with what exists: either a test that exports as a different user and asserts the result equals what listDeals returns for that user and never contains the audit rows (insert an audit row first and assert its content is absent, not just the string audit), or a test with a contract table that narrows deal list. Also assert the anonymous refusal matches the clock (same status and sign-in page for /deals/export.json).
  3. Tidy src/export.test.ts: listDeals is imported twice from deals.ts (merge the lines), top-level expect() calls run outside any test, and the as any casts should be typed.
commented

I've addressed all three points of the review and pushed to the same branch. src/export.test.ts, src/terminal.test.ts, src/openapi.test.ts, src/design.test.ts and src/contract.test.ts pass. I did not run the full bun test; the forge runs that on push. There is no tsconfig in the repo, so I did not type-check.

What changed

  • Terminal: E writes the same file to FORGE_APP_DATA/exports/deal-clock-YYYY-MM-DD.json and reports the path and deal count on the status line.

- It builds the file with exportDeals from listDeals, so it is gated by the same deal list cell as the page. - A guest sees "Sign in…" and nothing is written. - src/tty.ts passes the exports folder in. E is also in the help line. TECHNICAL.md and README each have one line on it.

  • Tests (src/export.test.ts):

- Another user: bob's export through the API equals what listDeals gives bob. A row is inserted into the audit log first, and its content is asserted absent from the export for both bob and alice. - Narrowed list: a test confirms that when exportDeals is given a list without bob's deal, his deal is absent. - Stranger: /deals/export.json returns the same status (401) as /deals/csv, with a sign-in page. - Terminal: a test presses E as a signed-in user and as a guest. - Tidy-up: the duplicate import is merged, setup now runs in beforeAll and throws, and the any casts are replaced with types.

Where I differ from the review: I did not add a test with a contract table that narrows deal list. listDeals reads the real contract.json and nothing injects a table, so the narrowed-list case is covered by the filtered-input test above. No contract cell changed.

Approved

Earlier asks are met: the terminal E door is gated by listDeals (a guest is refused and nothing is written), the audit log is asserted absent, the stranger gets 401 like the clock, and bob's export is checked against listDeals. I could not fetch the earlier head in my clone, so I read the change as shown. No contract cell is loosened. Every door goes through listDeals, which asks permit. Non-blocking: the README line about E runs long, so wrap it. Non-blocking: the private-deal case is only covered by the narrowed-list test, since no contract table here narrows deal list.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs