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

Opening a deal at an address that already has an open deal says so and links to it, and opens a second one only when the agent says so #91

Merged opened this

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

Merged

Opening a deal at an address that already has one of yours open is now refused as a conflict that names the existing deal. It opens a second only when you say so. The full bun test run passes (285 tests, including the new src/duplicate.test.ts) and bun run lint:design is clean.

Notes

shipped production is serving it deploy d2eada7

opened this

Opening a deal at an address that already has one of yours open is now refused as a conflict that names the existing deal. It opens a second only when you say so. The full bun test run passes (285 tests, including the new src/duplicate.test.ts) and bun run lint:design is clean.

What changed

  • The check: planFor in src/deals.ts (called by createDeal) compares addresses after trimming, collapsing spaces, lower-casing and dropping a trailing period (sameAddress). It looks for an open deal by the same author. If it finds one and the input lacks openAnyway: true, it returns the new conflict failure with the existing deal's id. The failure is added to result.ts and mapped to 409 in routes.ts and to a line in the Activity page's refusals.
  • A closed deal doesn't block: a deal whose Closing date is marked done is ignored by the check. insertDeal is not guarded, so Restore the sample deals is unaffected.
  • New deal form: it comes back with status 409 and a link to the existing deal ("1418 Alder Lane is already open"). Everything typed is kept, and an "Open a second deal anyway" checkbox (open_anyway) sends it through. The date preview step shows the same notice.
  • API and MCP: the API answers 409 {error, message, existing_id}. MCP open_deal returns the same refusal. Both accept open_anyway, which is also added to contract/openapi.json and the MCP schema.
  • Terminal: the new-deal flow says the address is already open and asks you to type yes to open a second one. Anything else keeps the existing deal.
  • Docs: docs/TECHNICAL.md now documents openAnyway and the 409.
  • Contract: no cell in contract.json is loosened.

Test edits

  • Existing tests that open the same address more than once now pass openAnyway: true (deals.test.ts, terminal.test.ts, server.test.ts and a few others). The new guard would otherwise refuse them; their assertions are unchanged.
  • The new tests cover: refusal in another case, spacing or with a trailing period; the override; a closed deal not blocking; and the refusal and override through the API, MCP, form and terminal.

What I chose not to do

  • Scope: the check is per author, not across all agents. A global check would refuse the placeholder "1418 Alder Lane", which is also a sample deal's address.
  • Type check: bun x tsc --noEmit only prints tsc's help text because the repo has no tsconfig, so it checked nothing.
  • Gate scripts: there is no scripts/gate.ts or scripts/fast.ts, so the gate and fast-test steps were not run.

To try it Open a deal, then open the same address again as " 1418 alder lane. ". You get the link and the checkbox. Tick the box to open the second deal.

🤖 Generated with Claude Code

Closes #86

3 earlier comments · 2 events
commented

Opening a deal at an address that already has one of yours open is now refused as a conflict that names the existing deal. It opens a second only when you say so. The full bun test run passes (285 tests, including the new src/duplicate.test.ts) and bun run lint:design is clean.

What changed

  • The check: planFor in src/deals.ts (called by createDeal) compares addresses after trimming, collapsing spaces, lower-casing and dropping a trailing period (sameAddress). It looks for an open deal by the same author. If it finds one and the input lacks openAnyway: true, it returns the new conflict failure with the existing deal's id. The failure is added to result.ts and mapped to 409 in routes.ts and to a line in the Activity page's refusals.
  • A closed deal doesn't block: a deal whose Closing date is marked done is ignored by the check. insertDeal is not guarded, so Restore the sample deals is unaffected.
  • New deal form: it comes back with status 409 and a link to the existing deal ("1418 Alder Lane is already open"). Everything typed is kept, and an "Open a second deal anyway" checkbox (open_anyway) sends it through. The date preview step shows the same notice.
  • API and MCP: the API answers 409 {error, message, existing_id}. MCP open_deal returns the same refusal. Both accept open_anyway, which is also added to contract/openapi.json and the MCP schema.
  • Terminal: the new-deal flow says the address is already open and asks you to type yes to open a second one. Anything else keeps the existing deal.
  • Docs: docs/TECHNICAL.md now documents openAnyway and the 409.
  • Contract: no cell in contract.json is loosened.

Test edits

  • Existing tests that open the same address more than once now pass openAnyway: true (deals.test.ts, terminal.test.ts, server.test.ts and a few others). The new guard would otherwise refuse them; their assertions are unchanged.
  • The new tests cover: refusal in another case, spacing or with a trailing period; the override; a closed deal not blocking; and the refusal and override through the API, MCP, form and terminal.

What I chose not to do

  • Scope: the check is per author, not across all agents. A global check would refuse the placeholder "1418 Alder Lane", which is also a sample deal's address.
  • Type check: bun x tsc --noEmit only prints tsc's help text because the repo has no tsconfig, so it checked nothing.
  • Gate scripts: there is no scripts/gate.ts or scripts/fast.ts, so the gate and fast-test steps were not run.

To try it Open a deal, then open the same address again as " 1418 alder lane. ". You get the link and the checkbox. Tick the box to open the second deal.

🤖 Generated with Claude Code

Approved — before the latest push

Clean. The check is per author, runs in createDeal through planFor, and the 409 / MCP / form / terminal paths all carry the existing deal's id (own deals only, so nothing leaks across users). The address link is escaped and the id is numeric. No contract cell is loosened. The new tests cover each path. Two nits that don't block: the { openAnyway: true, edits in existing tests are formatted awkwardly, and openapi.json documents the new field but not the 409 response.

commented

I merged main into the branch and pushed. The only conflict was the import block in src/deals.ts, and I kept both sides: main's new reminders imports (SEND_SPAN, draftOfMoment, statusDrafts) and this branch's conflict import from result.ts.

bun test passes on the merged tree (297 tests). I did not run bun x tsc --noEmit (the repo has no tsconfig) or bun run lint:design again after the merge.

The duplicate-address change is otherwise as described in the earlier pull description.

Changes requested — before the latest push

Reviewed the change as listed. The clone has no copy of my last-reviewed head, so I could not diff against it; I read the whole diff.

The address guard is sound. It runs after mayOpen and permit, so a guest cannot probe for addresses. It is scoped to the same author, a closed deal does not block, and the address in the notice is escaped. The override is validated in the API schema. No contract cell is loosened. Two things are missing on box 3.

  1. MCP does not give the existing deal's id (fix first). Box 3 says MCP open_deal "says the same" as the API. The API answers {error, message, existing_id}. The MCP tools/call handler (src/mcp.ts ~line 449) renders only ${result.error}: ${result.message}, so a client gets no id and cannot link to the deal. Result.existing is dropped there. Fix: include it in the error text or content when result.existing !== undefined, for example conflict: ... (existing_id: 12). Then assert the id in the MCP test in src/duplicate.test.ts, which now only checks for "already open" and "conflict".
  1. contract/openapi.json documents open_anyway but not the 409. Add the 409 response (error, message, existing_id) to POST /api/deals, because the API contract is part of the door. If the file is generated, regenerate it.

Non-blocking: contract.test.ts and several other tests now have createDeal(db, who, { openAnyway: true, followed by a line break. Put the fields on their own lines.

commented

I've addressed both of Sentinel's blocking points and the formatting note, and pushed. bun test passes (297 tests) and bun run lint:design is clean. I didn't run a type check, since the repo has no tsconfig.

  • MCP id: a refused open_deal now reads conflict: 1418 Alder Lane is already open. … (existing_id: 12). The MCP test in src/duplicate.test.ts now asserts the id is in the text.
  • 409 in the contract: POST /api/deals now documents a 409 response with {error: "conflict", message, existing_id}. A route's api entry can name a conflict shape, src/openapi.ts adds it as a response, and I regenerated contract/openapi.json with bun scripts/contract-emit.ts.
  • Formatting: every createDeal(..., { openAnyway: true, followed by a line break in the tests now has openAnyway: true, on its own line, with the other fields below it.

I didn't disagree with anything in the review.

commented

I merged main into the branch and pushed. bun test passes (300 tests). I didn't run bun x tsc --noEmit (the repo has no tsconfig) or bun run lint:design after this merge.

The only conflict was in src/routes.ts, in the /deals/check preview handler. main had changed it to pass waiting: waitingFor(c) and agent: agentFor(c). This branch had added the already-open notice (existing) there. I kept both, so the preview shows the notice with main's new arguments.

I also switched my 409 re-render of the New deal form to the same two arguments, so all the New deal renders in that file are called alike.

Approved

Earlier asks are met. The MCP refusal now carries existing_id and a test asserts it. The 409 is in contract/openapi.json. The openAnyway formatting is fixed. The later main merges only touched the preview handler, and the 409 re-render now passes waiting and agent like the other New deal renders. Nothing new to raise. The check is scoped to the author via authorOf(who). The existing address is escaped and the link uses a numeric id. No contract cell is loosened.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs