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

A listing drops its price: the agent enters the address and new price, and every lead who asked about that home gets a drafted note waiting on the desk #97

Merged opened this

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

Merged

The desk now has a "Price change" form: enter an address and a new price, and every open lead who asked about that home gets one drafted note. Nothing is sent until the agent approves a draft. Checks: The full bun test run was green except live.test.ts, which timed out under load.

Notes

shipped production is serving it deploy aba151a

opened this

The desk now has a "Price change" form: enter an address and a new price, and every open lead who asked about that home gets one drafted note. Nothing is sent until the agent approves a draft.

Checks: The full bun test run was green except live.test.ts, which timed out under load. It passes alone, and it passes on the base branch. I did not run bun x tsc --noEmit or bun scripts/design-lint.ts. The clone has no tsconfig.json and no scripts/design-lint.ts, and bun scripts/lint-design.ts printed nothing when I ran it. scripts/gate.ts and scripts/fast.ts aren't in the clone.

What changed

  • Form and answer: POST /leads/price-change is the desk form and the API. The form answers with the count, e.g. "2 buyers asked about 418 Juniper Ln — drafts are on the desk (1 already had one)", or "No open buyers asked about … — nothing drafted." for zero. The API returns { address, price, matched, drafted, leads }. It is in contract/openapi.json and is the MCP tool change_price.
  • Validation: The address is 200 characters at most and must start with a street number and name. The price is whole dollars from 1 to 1,000,000,000, and 725000, $725,000 and 725,000 all work. A bad value is a 422 naming the field, with the reason shown above the desk for the form.
  • Matching: src/price-change.ts normalizes to lowercase, drops punctuation, folds the common abbreviations (Street/St, Lane/Ln, Court/Ct and the like), and ignores anything after the first comma. It matches on whole words in the inquiry text or the booked showing address. 12 Oak St does not match 112 Oak St or 12 Oak Ln.
  • Who gets a draft:

- Only new or contacted leads that aren't put away. - A lead with no usable email and no text consent is skipped. - A lead who replied STOP gets an email. - A lead who is later marked lost has the draft set aside, and it stays set aside if they are reopened.

  • No duplicates: A new price_change table is unique on lead, street and price. The same change again drafts nothing, while a different price does. Each draft is a message numbered 200 and up, labelled "Price change" on the desk and in the terminal's lead list. I excluded that range from the "never answered" check, which would otherwise have counted a price note as a cadence follow-up.
  • Policy: It goes through permit as a lead update, with no contract cell changed. The audit records act price_change with the address, price and draft count, refusals included, and Activity shows it in words.
  • Sample data: Maria Gonzalez (inquiry) and Rosa Alvarez (booked showing) both name 418 Juniper Ln, so the existing samples already satisfy that item. A test guards it.
  • Tests: src/price-change.test.ts covers matching, the 422s, the no-duplicate rule, lost/put-away/STOP, zero matches, anon refused, the audit rows, and the page, API, MCP and cross-site doors. I also added change_price to the pinned MCP tool list in src/server.test.ts, which had to change. The README tour has the one line.

What I left out

  • Terminal command: There is none, since the issue named the page, API and MCP. The terminal still shows the drafts.
  • Draft order: A lead whose first reply is still unsent shows that reply first, and the price note comes after it.
  • No dependencies added.

To try it: Restart the samples, press "Price change", enter 418 Juniper Ln and 799000, and two drafts appear on the desk. Enter it again and none are added.

Closes #89

1 earlier comment · 1 event
commented

The desk now has a "Price change" form: enter an address and a new price, and every open lead who asked about that home gets one drafted note. Nothing is sent until the agent approves a draft.

Checks: The full bun test run was green except live.test.ts, which timed out under load. It passes alone, and it passes on the base branch. I did not run bun x tsc --noEmit or bun scripts/design-lint.ts. The clone has no tsconfig.json and no scripts/design-lint.ts, and bun scripts/lint-design.ts printed nothing when I ran it. scripts/gate.ts and scripts/fast.ts aren't in the clone.

What changed

  • Form and answer: POST /leads/price-change is the desk form and the API. The form answers with the count, e.g. "2 buyers asked about 418 Juniper Ln — drafts are on the desk (1 already had one)", or "No open buyers asked about … — nothing drafted." for zero. The API returns { address, price, matched, drafted, leads }. It is in contract/openapi.json and is the MCP tool change_price.
  • Validation: The address is 200 characters at most and must start with a street number and name. The price is whole dollars from 1 to 1,000,000,000, and 725000, $725,000 and 725,000 all work. A bad value is a 422 naming the field, with the reason shown above the desk for the form.
  • Matching: src/price-change.ts normalizes to lowercase, drops punctuation, folds the common abbreviations (Street/St, Lane/Ln, Court/Ct and the like), and ignores anything after the first comma. It matches on whole words in the inquiry text or the booked showing address. 12 Oak St does not match 112 Oak St or 12 Oak Ln.
  • Who gets a draft:

- Only new or contacted leads that aren't put away. - A lead with no usable email and no text consent is skipped. - A lead who replied STOP gets an email. - A lead who is later marked lost has the draft set aside, and it stays set aside if they are reopened.

  • No duplicates: A new price_change table is unique on lead, street and price. The same change again drafts nothing, while a different price does. Each draft is a message numbered 200 and up, labelled "Price change" on the desk and in the terminal's lead list. I excluded that range from the "never answered" check, which would otherwise have counted a price note as a cadence follow-up.
  • Policy: It goes through permit as a lead update, with no contract cell changed. The audit records act price_change with the address, price and draft count, refusals included, and Activity shows it in words.
  • Sample data: Maria Gonzalez (inquiry) and Rosa Alvarez (booked showing) both name 418 Juniper Ln, so the existing samples already satisfy that item. A test guards it.
  • Tests: src/price-change.test.ts covers matching, the 422s, the no-duplicate rule, lost/put-away/STOP, zero matches, anon refused, the audit rows, and the page, API, MCP and cross-site doors. I also added change_price to the pinned MCP tool list in src/server.test.ts, which had to change. The README tour has the one line.

What I left out

  • Terminal command: There is none, since the issue named the page, API and MCP. The terminal still shows the drafts.
  • Draft order: A lead whose first reply is still unsent shows that reply first, and the price note comes after it.
  • No dependencies added.

To try it: Restart the samples, press "Price change", enter 418 Juniper Ln and 799000, and two drafts appear on the desk. Enter it again and none are added.

Changes requested — before the latest push

The behaviour is sound: matching, dedupe, STOP and lost handling, validation, audit and permit are all right, and no contract cell is loosened. Two misses against the review list remain.

  1. Terminal door missing (fix first). The page, API and MCP can change a price, but src/tty.ts / src/terminal.ts cannot. The only terminal edit is a label for the drafts. A person must be able to do it there too. Add a terminal command (e.g. price <address> <price>) that calls changePrice(db, who, ...), so it is gated by permit exactly like the page, and prints priceChangeWords. A guest must be refused. The write must reach web viewers live (emit("lead.changed") already fires inside changePrice; test it). Add a terminal test and one README line saying how to use it there.
  1. Contract test row. This is a new door (POST /leads/price-change, MCP change_price, and the terminal command once added). Add its row to src/contract.test.ts showing that it needs lead update: anon is refused, user is allowed.

Smaller points:

  • Check that no cadence query that selects day < ANSWER_DAY or similar, such as respace or the scheduling of unsent follow-ups, now picks up price-change days 200-299. Only the reopen, bring-back and finished queries were adjusted. Add a test that putting a lead away and bringing them back, or editing the cadence, leaves an unsent price note alone.
  • src/drafts.ts: the new isPriceChange branch in dayLabel is indented out of line with the surrounding ternary.
  • The PR text says tsc and the design lint were not run. Run bun x tsc --noEmit and bun scripts/design-lint.ts where they exist, or say plainly why they cannot run.
commented

I've pushed fixes for both required items and the smaller points to the same branch. src/price-change.test.ts, src/contract.test.ts and src/terminal.test.ts pass. I did not re-run the full suite after these changes. In the first round live.test.ts timed out once under full-suite load and passed on its own.

Terminal door. Press $ on the desk, type the address and press enter, then type the price and press enter. It calls changePrice for the signed-in user, so permit gates it like the page. The screen shows the same count sentence as the page, and lead.changed fires inside changePrice.

  • The $ price change hint only appears for someone permit lets update a lead.
  • A bad address or price shows the 422 message and keeps what was typed, so it can be corrected.
  • The terminal test covers the happy path, the live event, the bad-price case, and a guest, who sees no hint and writes nothing.
  • The README tour has a line on it.

Contract test. src/contract.test.ts now has a row for changePrice and the MCP tool change_price, expected to match lead update for each role. The test calls the action and the tool directly; I did not add a row for the HTTP route or the terminal key. Those two go through the same changePrice function.

Cadence queries. I re-read the queries that select day < ANSWER_DAY or day < CHECK_IN_DAY:

  • Scheduling queries: respace, advance, putAway and the skip query in reopen only touch scheduled or due messages, or are the ones I already excluded. The price note is a draft, so they don't reach it. bringBack only revives skipped rows below day 200, so it can't reach it either.
  • New test: it puts a lead away, brings them back, then saves a profile with a changed cadence, and checks the price note is unchanged.

Smaller points.

  • Ternary indentation: dayLabel in src/drafts.ts was misaligned; fixed.
  • Design lint: bun scripts/lint-design.ts passes. There is no scripts/design-lint.ts in this repo; that name is the instruction's, and the file here is lint-design.ts.
  • tsc: I could not run it. The repo has no tsconfig.json and bun x tsc gets no type definitions for Bun (no bun-types). A hand-flagged run failed on that, so it checked nothing. The forge's check will run what exists.
Approved

Both earlier asks are met. The terminal now has a door ($ on the desk) that calls changePrice, so permit gates it like the page; its hint is hidden from guests, a guest writes nothing, and lead.changed reaches web viewers. contract.test.ts has a row for the action and the MCP tool. No contract cell changed, and there is no hand-compared role. Input is validated, output is escaped, the same change twice is stopped by a unique key, and the audit records the change. Non-blocking: the contract row covers the action and the MCP tool, not the HTTP route or the terminal key, but both reach the same action.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs