Public: anyone can read this; the crew can change it.
The People page says when each person last got a message from the agent and about what, so "did I tell the lender?" is answered in one look #129
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/125-the-people-page-says-when-each-person-la → main 3 commits fork 1 thread · 1 unresolved
9 files
changed +130
−3
README.md +4 −1
| @@ -62,7 +62,10 @@ looks like today. | ||
| 62 | 62 | 9. **See People.** Open **People** in the header. Each person on your deals |
| 63 | 63 | appears once, with every open date they owe across all deals, soonest |
| 64 | 64 | first. Try Priya Nair, the lender on both 1418 Alder Lane and 9 Orchard Row. |
| 65 | Tap a number to call or text, an address to write. | |
| 65 | Each person also shows when you last sent them a reminder or notice, and | |
| 66 | about what ("Last heard Nov 6 · Financing, 12 Oak Lane"), or "Nothing sent | |
| 67 | yet"; declined and held drafts don't count. Tap a number to call or text, | |
| 68 | an address to write. In the terminal press P; over MCP ask for `list_people`. | |
| 66 | 69 | 10. **Set up your Profile.** Open **Profile** in the header and type your name, |
| 67 | 70 | brokerage, phone and email. They appear in the header, on the client |
| 68 | 71 | timeline and at the foot of every new reminder. (Only an admin can save |
contract/openapi.json +21
| @@ -682,6 +682,27 @@ | ||
| 682 | 682 | "type": "string" |
| 683 | 683 | } |
| 684 | 684 | }, |
| 685 | "last_sent": { | |
| 686 | "type": "object", | |
| 687 | "nullable": true, | |
| 688 | "description": "The most recent reminder or notice the agent approved and sent this person, across deals; null when none was sent. Declined, held and waiting drafts do not count.", | |
| 689 | "properties": { | |
| 690 | "sent_on": { | |
| 691 | "type": "string", | |
| 692 | "format": "date" | |
| 693 | }, | |
| 694 | "deal_id": { | |
| 695 | "type": "integer" | |
| 696 | }, | |
| 697 | "address": { | |
| 698 | "type": "string" | |
| 699 | }, | |
| 700 | "label": { | |
| 701 | "type": "string", | |
| 702 | "description": "The date the message was about." | |
| 703 | } | |
| 704 | } | |
| 705 | }, | |
| 685 | 706 | "owes": { |
| 686 | 707 | "type": "array", |
| 687 | 708 | "items": { |
src/lastsent.test.ts added +38
| @@ -0,0 +1,38 @@ | ||
| 1 | /** The People page says when each person last got a message the agent sent, and not for ones declined. */ | |
| 2 | import { expect, test } from "bun:test"; | |
| 3 | import { mkdtempSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { addDays, today } from "./dates.ts"; | |
| 7 | import { openDb } from "./db.ts"; | |
| 8 | import { createDeal, declineReminder, getDeal, listDeals, sendReminder } from "./deals.ts"; | |
| 9 | import { agent } from "./env.ts"; | |
| 10 | import { peoplePage } from "./pages/people.ts"; | |
| 11 | import { people } from "./people.ts"; | |
| 12 | import { drafts } from "./reminders.ts"; | |
| 13 | import type { Who } from "./who.ts"; | |
| 14 | ||
| 15 | const db = openDb(mkdtempSync(join(tmpdir(), "app-lastsent-"))); | |
| 16 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 17 | const made = createDeal(db, alice, { openAnyway: true, address: "12 Oak Lane", buyer: "Ann Buyer", seller: "Sam Seller", contractDate: addDays(today(), -10), closingDate: addDays(today(), 30) }); | |
| 18 | if (!made.ok) throw new Error(made.message); | |
| 19 | db.query("UPDATE party SET contact = '[email protected]', email = '[email protected]' WHERE deal_id = ?1 AND role = 'buyer'").run(made.value.id); | |
| 20 | db.query("UPDATE party SET contact = '[email protected]', email = '[email protected]' WHERE deal_id = ?1 AND role = 'seller'").run(made.value.id); | |
| 21 | const deal = () => { const g = getDeal(db, alice, { id: made.value.id }); if (!g.ok) throw new Error(g.message); return g.value; }; | |
| 22 | const everyone = () => { const l = listDeals(db, alice); if (!l.ok) throw new Error(l.message); return people(l.value, today()); }; | |
| 23 | const ann = () => everyone().find((p) => p.email === "[email protected]")!; | |
| 24 | const page = () => peoplePage({ who: alice, people: everyone(), on: today() }); | |
| 25 | ||
| 26 | test("nothing sent yet, then a declined draft still counts for nothing, then a sent one shows", () => { | |
| 27 | expect(ann().last_sent).toBeNull(); | |
| 28 | expect(page()).toContain("Nothing sent yet"); | |
| 29 | const [first, second] = drafts(deal(), agent).filter((r) => r.party_name === "Ann Buyer"); | |
| 30 | expect(first && second).toBeTruthy(); | |
| 31 | expect(declineReminder(db, alice, { deadlineId: first!.deadline_id, partyId: first!.party_id, moment: first!.moment, reason: "called them" }).ok).toBe(true); | |
| 32 | expect(ann().last_sent).toBeNull(); | |
| 33 | expect(sendReminder(db, alice, { deadlineId: second!.deadline_id, partyId: second!.party_id, moment: second!.moment, agent }).ok).toBe(true); | |
| 34 | expect(ann().last_sent).toEqual({ sent_on: today(), deal_id: made.value.id, address: "12 Oak Lane", label: second!.label }); | |
| 35 | expect(page()).toContain(`Last heard`); | |
| 36 | expect(page()).toContain(`12 Oak Lane`); | |
| 37 | expect(everyone().find((p) => p.email === "[email protected]")!.last_sent).toBeNull(); | |
| 38 | }); |
src/pages/people.ts +6
| @@ -16,9 +16,15 @@ import { URGENCY_LABEL } from "./sheet.ts"; | ||
| 16 | 16 | const owedRow = (o: Person["owes"][number], on: string): string => |
| 17 | 17 | `<li><a class="week-row" href="/deals/${o.deal_id}"><span class="week-what"><b>${escape(o.label)}</b><small class="muted">${escape(o.address)} · ${escape(spoken(o.due))} · ${escape(relative(o.due, on))}</small></span><span class="badge" data-u="${o.urgency}">${URGENCY_LABEL[o.urgency]}</span></a></li>`; |
| 18 | 18 | |
| 19 | const lastHeard = (l: Person["last_sent"]): string => | |
| 20 | !l | |
| 21 | ? `<p class="muted">Nothing sent yet</p>` | |
| 22 | : `<p class="muted">Last heard ${escape(spoken(l.sent_on))} · <a href="/deals/${l.deal_id}">${escape(l.label)}, ${escape(l.address)}</a></p>`; | |
| 23 | ||
| 19 | 24 | const person = (p: Person, on: string): string => `<section class="card person"> |
| 20 | 25 | <h2>${escape(p.name)}</h2> |
| 21 | 26 | <p class="muted">${escape(p.roles.join(", "))}${[p.email, p.phone, ...(p.email === "" && p.phone === "" ? [p.contact] : [])].filter((v) => v !== "").map((v) => ` · ${partyContact(v)}`).join("")}</p> |
| 27 | ${lastHeard(p.last_sent)} | |
| 22 | 28 | ${p.owes.length === 0 ? `<p class="muted">Nothing open</p>` : `<ul class="week-list">${p.owes.map((o) => owedRow(o, on)).join("")}</ul>`} |
| 23 | 29 | </section>`; |
| 24 | 30 |
src/people.test.ts +14
| @@ -8,6 +8,7 @@ const deal = (id: number, address: string, parties: [number, string, string, str | ||
| 8 | 8 | id, |
| 9 | 9 | address, |
| 10 | 10 | closed, |
| 11 | sent: [], | |
| 11 | 12 | parties: parties.map(([pid, role, name, contact]) => ({ id: pid, deal_id: id, role, name, contact, email: "", phone: "" })), |
| 12 | 13 | deadlines: dates.map(([did, owes, label, due, done_at]) => ({ id: did, owes, label, due, done_at, waived_at: null })), |
| 13 | 14 | }) as unknown as DealView; |
| @@ -43,3 +44,16 @@ test("people who owe nothing open come last; a closed deal's dates are not chase | ||
| 43 | 44 | expect(all.map((p) => p.name)).toEqual(["Priya N., Coastline", "Tess", "Zed"]); |
| 44 | 45 | expect(all.at(-1)!.owes).toEqual([]); |
| 45 | 46 | }); |
| 47 | ||
| 48 | const sent = (id: number, deal_id: number, party_id: number, label: string, sent_at: string) => ({ id, deal_id, party_id, label, sent_at }); | |
| 49 | const withSent = (d: DealView, ...m: ReturnType<typeof sent>[]): DealView => ({ ...d, sent: m }) as unknown as DealView; | |
| 50 | ||
| 51 | test("last_sent: nothing sent is null; the newest sent message across deals wins; same name, other contact is not them", () => { | |
| 52 | const a = withSent(deal(1, "B Street", [[1, "lender", "Priya Nair", "[email protected]"], [2, "lender", "Priya Nair", "[email protected]"]], []), sent(1, 1, 1, "Financing", "2026-11-06T09:00:00Z")); | |
| 53 | const b = withSent(deal(2, "A Street", [[5, "lender", "Priya Nair", "[email protected]"]], []), sent(2, 2, 5, "Appraisal", "2026-11-07T09:00:00Z")); | |
| 54 | expect(people([deal(1, "B Street", [[1, "lender", "Priya Nair", "[email protected]"]], [])], on)[0]!.last_sent).toBeNull(); | |
| 55 | const all = people([a, b], on); | |
| 56 | expect(all.find((p) => p.contact === "[email protected]")!.last_sent).toEqual({ sent_on: "2026-11-07", deal_id: 2, address: "A Street", label: "Appraisal" }); | |
| 57 | expect(all.find((p) => p.contact === "[email protected]")!.last_sent).toBeNull(); | |
| 58 | expect(people([a], on).find((p) => p.contact === "[email protected]")!.last_sent?.sent_on).toBe("2026-11-06"); | |
| 59 | }); |
src/people.ts +22 −2
| @@ -18,6 +18,15 @@ export interface Owed { | ||
| 18 | 18 | readonly urgency: Urgency; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | /** The newest message the agent approved and sent to a person: the day, and the deal and date it was about. */ | |
| 22 | export interface LastSent { | |
| 23 | /** ISO date. */ | |
| 24 | readonly sent_on: string; | |
| 25 | readonly deal_id: number; | |
| 26 | readonly address: string; | |
| 27 | readonly label: string; | |
| 28 | } | |
| 29 | ||
| 21 | 30 | export interface Person { |
| 22 | 31 | /** The name on the person's most recently added party row. */ |
| 23 | 32 | readonly name: string; |
| @@ -29,6 +38,8 @@ export interface Person { | ||
| 29 | 38 | readonly roles: readonly string[]; |
| 30 | 39 | /** Open dates they owe, soonest first, then by address. */ |
| 31 | 40 | readonly owes: readonly Owed[]; |
| 41 | /** Their most recent sent reminder or notice across deals; null when none was sent. */ | |
| 42 | readonly last_sent: LastSent | null; | |
| 32 | 43 | } |
| 33 | 44 | |
| 34 | 45 | /** What identifies a party: their email and phone, ignoring case and outer spaces; with neither, their contact, else their name. */ |
| @@ -41,7 +52,10 @@ export const personKeys = (p: { name: string; contact: string; email?: string; p | ||
| 41 | 52 | /** The one key a party is shown under in a sentence: its email, else phone, else contact, else name. */ |
| 42 | 53 | export const personKey = (p: { name: string; contact: string; email?: string; phone?: string }): string => personKeys(p)[0]!; |
| 43 | 54 | |
| 44 | interface One { name: string; newest: number; contact: string; email: string; phone: string; roles: Set<PartyRole>; owes: Map<number, Owed> } | |
| 55 | type Last = (LastSent & { at: string; id: number }) | null; | |
| 56 | const newer = (a: Last, b: Last): Last => (a === null ? b : b === null ? a : b.at > a.at || (b.at === a.at && b.id > a.id) ? b : a); | |
| 57 | ||
| 58 | interface One { name: string; newest: number; contact: string; email: string; phone: string; roles: Set<PartyRole>; owes: Map<number, Owed>; last: (LastSent & { at: string; id: number }) | null } | |
| 45 | 59 | |
| 46 | 60 | /** Two parties are one person when they share an email or a phone, even if one row has only the phone and another both. */ |
| 47 | 61 | export function people(deals: readonly DealView[], on: string): Person[] { |
| @@ -54,13 +68,14 @@ export function people(deals: readonly DealView[], on: string): Person[] { | ||
| 54 | 68 | into.email = from.email; |
| 55 | 69 | into.phone = from.phone; |
| 56 | 70 | } |
| 71 | into.last = newer(into.last, from.last); | |
| 57 | 72 | for (const r of from.roles) into.roles.add(r); |
| 58 | 73 | for (const [id, o] of from.owes) into.owes.set(id, o); |
| 59 | 74 | }; |
| 60 | 75 | for (const deal of deals) { |
| 61 | 76 | for (const party of deal.parties) { |
| 62 | 77 | const keys = personKeys(party); |
| 63 | let one: One = { name: party.name, newest: -1, contact: party.contact.trim(), email: party.email.trim(), phone: party.phone.trim(), roles: new Set(), owes: new Map() }; | |
| 78 | let one: One = { name: party.name, newest: -1, contact: party.contact.trim(), email: party.email.trim(), phone: party.phone.trim(), roles: new Set(), owes: new Map(), last: null }; | |
| 64 | 79 | for (const key of keys) { |
| 65 | 80 | const found = byKey.get(key); |
| 66 | 81 | if (found !== undefined && found !== one) { |
| @@ -78,6 +93,10 @@ export function people(deals: readonly DealView[], on: string): Person[] { | ||
| 78 | 93 | one.phone = party.phone.trim(); |
| 79 | 94 | } |
| 80 | 95 | one.roles.add(party.role); |
| 96 | // Only sent messages are in `deal.sent`; declined and held ones live apart. | |
| 97 | for (const m of deal.sent) { | |
| 98 | if (m.party_id === party.id) one.last = newer(one.last, { sent_on: m.sent_at.slice(0, 10), deal_id: deal.id, address: deal.address, label: m.label, at: m.sent_at, id: m.id }); | |
| 99 | } | |
| 81 | 100 | // A closed deal is off the clock: nothing on it is chased. |
| 82 | 101 | if (deal.closed || deal.fell_through) continue; |
| 83 | 102 | for (const d of deal.deadlines) { |
| @@ -100,6 +119,7 @@ export function people(deals: readonly DealView[], on: string): Person[] { | ||
| 100 | 119 | email: p.email, |
| 101 | 120 | phone: p.phone, |
| 102 | 121 | roles: [...p.roles].map((r) => PARTY_LABEL[r]), |
| 122 | last_sent: p.last === null ? null : { sent_on: p.last.sent_on, deal_id: p.last.deal_id, address: p.last.address, label: p.last.label }, | |
| 103 | 123 | owes: [...p.owes.values()].sort((a, b) => a.due.localeCompare(b.due) || a.address.localeCompare(b.address)), |
| 104 | 124 | })) |
| 105 | 125 | .sort((a, b) => { |
src/routes.ts +6
| @@ -211,6 +211,12 @@ export const PERSON: Schema = { | ||
| 211 | 211 | phone: { type: "string" }, |
| 212 | 212 | contact: CONTACT, |
| 213 | 213 | roles: { type: "array", items: { type: "string" } }, |
| 214 | last_sent: { | |
| 215 | type: "object", | |
| 216 | nullable: true, | |
| 217 | description: "The most recent reminder or notice the agent approved and sent this person, across deals; null when none was sent. Declined, held and waiting drafts do not count.", | |
| 218 | properties: { sent_on: DATE, deal_id: { type: "integer" }, address: { type: "string" }, label: { type: "string", description: "The date the message was about." } }, | |
| 219 | }, | |
| 214 | 220 | owes: { |
| 215 | 221 | type: "array", |
| 216 | 222 | items: { |
src/terminal.test.ts +18
| @@ -523,11 +523,29 @@ test("P lists each person once with the dates they owe across deals; a guest is | ||
| 523 | 523 | expect(screen).toContain("1 Shared Lane"); |
| 524 | 524 | expect(screen).toContain("2 Shared Lane"); |
| 525 | 525 | expect(screen).toContain("Nothing open"); |
| 526 | expect(screen).toContain("Nothing sent yet"); | |
| 526 | 527 | const guest = terminal(own, { role: "anon" }, context); |
| 527 | 528 | guest.press("P"); |
| 528 | 529 | expect(lines(guest).join("\n")).not.toContain("Lena Lender"); |
| 529 | 530 | }); |
| 530 | 531 | |
| 532 | test("P shows when each person last got a sent message, and about what", () => { | |
| 533 | const own = openDb(mkdtempSync(join(tmpdir(), "app-terminal-lastsent-"))); | |
| 534 | const made = createDeal(own, alice, { openAnyway: true, address: "9 Heard Way", buyer: "Bea Buyer", seller: "Sol Seller", contractDate: addDays(today(), -5), closingDate: addDays(today(), 30) }); | |
| 535 | if (!made.ok) throw new Error(made.message); | |
| 536 | const got = getDeal(own, alice, { id: made.value.id }); | |
| 537 | if (!got.ok) throw new Error(got.message); | |
| 538 | const bea = got.value.parties.find((p) => p.name === "Bea Buyer")!; | |
| 539 | const date = got.value.deadlines[0]!; | |
| 540 | own.query("UPDATE party SET contact = '[email protected]', email = '[email protected]' WHERE id = ?1").run(bea.id); | |
| 541 | expect(sendReminder(own, alice, { deadlineId: date.id, partyId: bea.id, moment: "before" }).ok).toBe(true); | |
| 542 | const t = terminal(own, alice, context); | |
| 543 | t.press("P"); | |
| 544 | const screen = lines(t).join("\n"); | |
| 545 | expect(screen).toContain(`Last heard ${spoken(today())} · ${date.label}, 9 Heard Way`); | |
| 546 | expect(screen).toContain("Nothing sent yet"); | |
| 547 | }); | |
| 548 | ||
| 531 | 549 | test("the deal view lists a date that falls after closing, in words", () => { |
| 532 | 550 | const other = createDeal(db, alice, { |
| 533 | 551 | openAnyway: true, |
src/terminal.ts +1
| @@ -748,6 +748,7 @@ export function terminal( | ||
| 748 | 748 | if (all.length === 0) lines.push(dim("No one yet: add a deal and its parties.")); |
| 749 | 749 | for (const p of all) { |
| 750 | 750 | lines.push(`${bold(p.name)} ${dim(`${p.roles.join(", ")}${reachedAt(p) === "" ? "" : ` · ${reachedAt(p)}`}`)}`); |
| 751 | lines.push(dim(p.last_sent === null ? " Nothing sent yet" : ` Last heard ${spoken(p.last_sent.sent_on)} · ${p.last_sent.label}, ${p.last_sent.address}`)); | |
| 751 | 752 | if (p.owes.length === 0) lines.push(dim(" Nothing open")); |
| 752 | 753 | for (const o of p.owes) |
| 753 | 754 | lines.push(` ${tint(o.urgency, `${spoken(o.due).padEnd(12)} ${relative(o.due, day).padEnd(12)}`)} ${o.label} — ${o.address}`); |
new above
offline
This says the terminal P view shows it, but src/terminal.ts people view never reads last_sent. Add the line there (and a test), or the page and terminal disagree.