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

The agent brings their deals back from a downloaded deal-clock file on the Profile page, so the download is a real way to move or recover their book #181

Merged opened this

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

Merged

The Profile page now has Bring deals back from a file, so a downloaded deal-clock file can restore an agent's book on a new laptop or account. The new import tests, the contract, openapi, security, server, restore, sample and upgrade suites, and bun run lint:design all pass.

Notes

shipped production is serving it deploy d2eada7

opened this

The Profile page now has Bring deals back from a file, so a downloaded deal-clock file can restore an agent's book on a new laptop or account.

The new import tests, the contract, openapi, security, server, restore, sample and upgrade suites, and bun run lint:design all pass. I did not run the full suite or bun x tsc --noEmit: the repo has no tsconfig.json, so tsc only printed its help text, and there is no scripts/gate.ts or scripts/fast.ts.

What changed

  • Form: the Profile page has a file input and a button. It is a plain multipart POST to /deals/import, behind the same same-origin check as every other mutation. The answer page says "Brought back N deals, skipped M already here", links to the clock, and states in one sentence that sent and declined messages are not brought back.
  • API: POST /api/deals/import takes the file as its JSON body and is in /openapi.json.
  • Validation: src/import.ts reads the whole file before anything is written.

- version must equal EXPORT_VERSION. - The file may hold at most EXPORT_MAX deals. - A body over 5 MB is a 413. - Any bad deal makes the whole file a 422 naming the place, for example "Deal 3 of the file: …", and nothing is written.

  • Reused checks: each deal goes through plan, the check opening a deal uses. Parties go through partyText, which I exported from src/deals.ts for this. Closing time and place use the existing closingTime and closingPlace.
  • Writes: all deals go in one transaction.

- The author is whoever imports, never the id or author in the file. - Dates keep their done and waived state, notes and moves. Fell-through and closed deals stay so. - permit is asked for deal create; no contract cell changed. - Each deal imported is audited as deal.import, and a refused attempt is audited too.

  • Docs: README "Make it yours" says how to bring deals back, and docs/TECHNICAL.md describes the import.

Tests (src/import.test.ts)

  • Export then import into an empty agent gives the same deals, covering side, cash, price, closing time and place, parties, dates, notes, moves, fell-through and closed.
  • Importing twice adds nothing.
  • A wrong version, a bad date in deal 3, an empty address and an oversized body are each refused with nothing written.
  • A file claiming another author is still imported as the importer's, and the other agents' deals are unchanged.
  • A stranger gets 401, a cross-site post is refused, and the Profile page offers the form.

Things to know

  • "Already here" means a deal by the importer or a sample deal with the same address and contract date. Today's export holds every deal the agent can read, so a file includes other agents' deals and the shared samples. The samples are skipped. Another agent's deal is brought in as the importer's own copy. I did not narrow the export, since that is outside this issue.
  • A deal's "what is owed" text is not in the export. Standard dates get their usual text back, and custom dates come back with it empty.
  • created_at is the import time, not the file's.
  • A deal missing a buyer or seller party still validates, using a placeholder name for the check only. The parties written are exactly the file's.
  • I added no dependencies.

To try it: sign in, open Profile, download your deals, then choose that file under "Bring deals back from a file". The page reports everything skipped as already here. Signed in as a different agent, the same file brings the deals in as theirs.

🤖 Generated with Claude Code

Closes #179

2 earlier comments · 2 events
commented

The Profile page now has Bring deals back from a file, so a downloaded deal-clock file can restore an agent's book on a new laptop or account.

The new import tests, the contract, openapi, security, server, restore, sample and upgrade suites, and bun run lint:design all pass. I did not run the full suite or bun x tsc --noEmit: the repo has no tsconfig.json, so tsc only printed its help text, and there is no scripts/gate.ts or scripts/fast.ts.

What changed

  • Form: the Profile page has a file input and a button. It is a plain multipart POST to /deals/import, behind the same same-origin check as every other mutation. The answer page says "Brought back N deals, skipped M already here", links to the clock, and states in one sentence that sent and declined messages are not brought back.
  • API: POST /api/deals/import takes the file as its JSON body and is in /openapi.json.
  • Validation: src/import.ts reads the whole file before anything is written.

- version must equal EXPORT_VERSION. - The file may hold at most EXPORT_MAX deals. - A body over 5 MB is a 413. - Any bad deal makes the whole file a 422 naming the place, for example "Deal 3 of the file: …", and nothing is written.

  • Reused checks: each deal goes through plan, the check opening a deal uses. Parties go through partyText, which I exported from src/deals.ts for this. Closing time and place use the existing closingTime and closingPlace.
  • Writes: all deals go in one transaction.

- The author is whoever imports, never the id or author in the file. - Dates keep their done and waived state, notes and moves. Fell-through and closed deals stay so. - permit is asked for deal create; no contract cell changed. - Each deal imported is audited as deal.import, and a refused attempt is audited too.

  • Docs: README "Make it yours" says how to bring deals back, and docs/TECHNICAL.md describes the import.

Tests (src/import.test.ts)

  • Export then import into an empty agent gives the same deals, covering side, cash, price, closing time and place, parties, dates, notes, moves, fell-through and closed.
  • Importing twice adds nothing.
  • A wrong version, a bad date in deal 3, an empty address and an oversized body are each refused with nothing written.
  • A file claiming another author is still imported as the importer's, and the other agents' deals are unchanged.
  • A stranger gets 401, a cross-site post is refused, and the Profile page offers the form.

Things to know

  • "Already here" means a deal by the importer or a sample deal with the same address and contract date. Today's export holds every deal the agent can read, so a file includes other agents' deals and the shared samples. The samples are skipped. Another agent's deal is brought in as the importer's own copy. I did not narrow the export, since that is outside this issue.
  • A deal's "what is owed" text is not in the export. Standard dates get their usual text back, and custom dates come back with it empty.
  • created_at is the import time, not the file's.
  • A deal missing a buyer or seller party still validates, using a placeholder name for the check only. The parties written are exactly the file's.
  • I added no dependencies.

To try it: sign in, open Profile, download your deals, then choose that file under "Bring deals back from a file". The page reports everything skipped as already here. Signed in as a different agent, the same file brings the deals in as theirs.

🤖 Generated with Claude Code

Changes requested — before the latest push

The import is well built: one transaction, every deal checked before any write, author taken from the signed-in identity, body capped by bytes read, and no contract cell changed. Two things block it.

  1. The terminal has no way to bring deals back. The export is reachable from the page, the API, the MCP tool export_deals and E in src/tty.ts. The import is reachable only from the page and the API. Fix first: add an import to the terminal that reads a file from FORGE_APP_DATA/exports/ (where E writes) and calls importDeals. Gate it exactly as the page does, add a test, and say how to use it in the README. If it is cheap, add an MCP import_deals tool too, with the same cap.
  1. The new door has no row in src/contract.test.ts. The diff does not touch that file. Add POST /api/deals/import (deal create, least user) and POST /deals/import there, if the table lists doors that way.

Smaller points:

  • importDeals writes the per-deal audit rows after the transaction commits, so a crash between the two leaves deals with no deal.import row. Write them inside the transaction.
  • Add a test that a file with a missing buyer or seller party round-trips the parties exactly. It is the placeholder-name path, and nothing covers it.

Boxes 1, 2, 3, 4, 5 and 7 are met. Box 6 lacks a terminal test, which is only implied by the issue text, so I treat it as met.

commented

I addressed the requested changes, except the MCP import_deals tool, which I skipped. The import, contract, terminal, export, server, openapi, security and design tests pass, and so does the design lint. I didn't run the full suite, and bun x tsc --noEmit can't run here because the repo has no tsconfig.json.

  • Terminal: O on the clock or week view brings deals back from a file in FORGE_APP_DATA/exports/, the folder E writes to.

- It asks for a file name; entering nothing takes the newest file. - Only a bare *.json name is accepted, so no path can leave the folder. - It refuses a file over 5 MB. - It checks mayOpen first, as the page's create does, then calls the same importDeals through a new importText in src/import.ts. - The hint line lists O, and the README and docs/TECHNICAL.md say how to use it.

  • Contract test: src/contract.test.ts now has a row that posts an empty valid file to both POST /api/deals/import and POST /deals/import. It checks that every identity gets what permit(who, "deal", "create") says.
  • Audit: the deal.import rows are now written inside the same transaction as the deals, so a crash leaves both or neither.
  • Tests in src/import.test.ts:

- A deal whose only party is a lender comes back with exactly that party, which covers the placeholder-name path. - The terminal imports the newest file, refuses a wrong version, refuses ../../etc/passwd as a file name, and refuses an anonymous user.

MCP tool: I did not add an import_deals tool. /mcp reads at most 64 KB, so an import tool there would not have the same cap, and raising that door's limit for one tool seemed a bigger change than the issue asks. docs/TECHNICAL.md says so.

No contract cell changed.

🤖 Generated with Claude Code

Approved

Earlier asks are met. The terminal now has O, gated by mayOpen, reading only a bare *.json name from the exports folder, with a 5 MB cap and a test that rejects ../../etc/passwd and a guest. src/contract.test.ts has a row for both import doors that checks every identity against permit. Audit rows are written in the same transaction as the deals. The author is always the importer, bodies are capped by bytes read, and no contract cell changed. Non-blocking: there is no MCP import tool. The reason in TECHNICAL.md (the 64 KB cap on /mcp) is acceptable.

commented

Left #179 open: 1 unticked item remain (Each deal is created as the signed-in agent's own (author is who imports, never the id or author in the file), with its side, cash flag, closing time and place, figures, parties, dates with their done/waived state and notes. Fell-through and closed deals stay so. Asking permit for deal create, as today's create does; no contract cell changes.).

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs