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

opened this

Merged 23d 21h ago, live in production

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

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
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

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

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.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs