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

Merged opened this

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

Merged

mason/deal-clock:mason/125-the-people-page-says-when-each-person-la → main 3 commits fork 1 thread · 1 unresolved

  • Merged. mason/125-the-people-page-says-when-each-person-la was merged into main as 76e3313.

Review

Sign in to review this change.
9 files changed +130 −3
README.md +4 −1
@@ -62,7 +62,10 @@ looks like today.
6262 9. **See People.** Open **People** in the header. Each person on your deals
6363 appears once, with every open date they owe across all deals, soonest
6464 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`.

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.

6669 10. **Set up your Profile.** Open **Profile** in the header and type your name,
6770 brokerage, phone and email. They appear in the header, on the client
6871 timeline and at the foot of every new reminder. (Only an admin can save
contract/openapi.json +21
@@ -682,6 +682,27 @@
682682 "type": "string"
683683 }
684684 },
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 },
685706 "owes": {
686707 "type": "array",
687708 "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";
1616 const owedRow = (o: Person["owes"][number], on: string): string =>
1717 `<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>`;
1818
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
1924 const person = (p: Person, on: string): string => `<section class="card person">
2025 <h2>${escape(p.name)}</h2>
2126 <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)}
2228 ${p.owes.length === 0 ? `<p class="muted">Nothing open</p>` : `<ul class="week-list">${p.owes.map((o) => owedRow(o, on)).join("")}</ul>`}
2329 </section>`;
2430
src/people.test.ts +14
@@ -8,6 +8,7 @@ const deal = (id: number, address: string, parties: [number, string, string, str
88 id,
99 address,
1010 closed,
11 sent: [],
1112 parties: parties.map(([pid, role, name, contact]) => ({ id: pid, deal_id: id, role, name, contact, email: "", phone: "" })),
1213 deadlines: dates.map(([did, owes, label, due, done_at]) => ({ id: did, owes, label, due, done_at, waived_at: null })),
1314 }) as unknown as DealView;
@@ -43,3 +44,16 @@ test("people who owe nothing open come last; a closed deal's dates are not chase
4344 expect(all.map((p) => p.name)).toEqual(["Priya N., Coastline", "Tess", "Zed"]);
4445 expect(all.at(-1)!.owes).toEqual([]);
4546 });
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 {
1818 readonly urgency: Urgency;
1919 }
2020
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
2130 export interface Person {
2231 /** The name on the person's most recently added party row. */
2332 readonly name: string;
@@ -29,6 +38,8 @@ export interface Person {
2938 readonly roles: readonly string[];
3039 /** Open dates they owe, soonest first, then by address. */
3140 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;
3243 }
3344
3445 /** 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
4152 /** The one key a party is shown under in a sentence: its email, else phone, else contact, else name. */
4253 export const personKey = (p: { name: string; contact: string; email?: string; phone?: string }): string => personKeys(p)[0]!;
4354
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 }
4559
4660 /** Two parties are one person when they share an email or a phone, even if one row has only the phone and another both. */
4761 export function people(deals: readonly DealView[], on: string): Person[] {
@@ -54,13 +68,14 @@ export function people(deals: readonly DealView[], on: string): Person[] {
5468 into.email = from.email;
5569 into.phone = from.phone;
5670 }
71 into.last = newer(into.last, from.last);
5772 for (const r of from.roles) into.roles.add(r);
5873 for (const [id, o] of from.owes) into.owes.set(id, o);
5974 };
6075 for (const deal of deals) {
6176 for (const party of deal.parties) {
6277 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 };
6479 for (const key of keys) {
6580 const found = byKey.get(key);
6681 if (found !== undefined && found !== one) {
@@ -78,6 +93,10 @@ export function people(deals: readonly DealView[], on: string): Person[] {
7893 one.phone = party.phone.trim();
7994 }
8095 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 }
81100 // A closed deal is off the clock: nothing on it is chased.
82101 if (deal.closed || deal.fell_through) continue;
83102 for (const d of deal.deadlines) {
@@ -100,6 +119,7 @@ export function people(deals: readonly DealView[], on: string): Person[] {
100119 email: p.email,
101120 phone: p.phone,
102121 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 },
103123 owes: [...p.owes.values()].sort((a, b) => a.due.localeCompare(b.due) || a.address.localeCompare(b.address)),
104124 }))
105125 .sort((a, b) => {
src/routes.ts +6
@@ -211,6 +211,12 @@ export const PERSON: Schema = {
211211 phone: { type: "string" },
212212 contact: CONTACT,
213213 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 },
214220 owes: {
215221 type: "array",
216222 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
523523 expect(screen).toContain("1 Shared Lane");
524524 expect(screen).toContain("2 Shared Lane");
525525 expect(screen).toContain("Nothing open");
526 expect(screen).toContain("Nothing sent yet");
526527 const guest = terminal(own, { role: "anon" }, context);
527528 guest.press("P");
528529 expect(lines(guest).join("\n")).not.toContain("Lena Lender");
529530 });
530531
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
531549 test("the deal view lists a date that falls after closing, in words", () => {
532550 const other = createDeal(db, alice, {
533551 openAnyway: true,
src/terminal.ts +1
@@ -748,6 +748,7 @@ export function terminal(
748748 if (all.length === 0) lines.push(dim("No one yet: add a deal and its parties."));
749749 for (const p of all) {
750750 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}`));
751752 if (p.owes.length === 0) lines.push(dim(" Nothing open"));
752753 for (const o of p.owes)
753754 lines.push(` ${tint(o.urgency, `${spoken(o.due).padEnd(12)} ${relative(o.due, day).padEnd(12)}`)} ${o.label} — ${o.address}`);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs