Public: anyone can read this; the crew can change it.
People flags someone who owes a date in the next three days and has heard nothing from you in a week #226
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/223-people-flags-someone-who-owes-a-date-in → main 8 commits fork
8 files
changed +100
−14
docs/design/areas/people.md +1
| @@ -4,3 +4,4 @@ Classes on `/people`, the list of everyone on the agent's deals with the dates t | ||
| 4 | 4 | |
| 5 | 5 | - `.person` — one person's card: name, roles and contact, then their open dates or "Nothing open". |
| 6 | 6 | - `.contact-link` — a party's email, phone or Text link on `/people` and the deal page's party list; at least `--size-tap` tall. |
| 7 | - `.person-nudge` — an amber line under a person's name when they owe a date within three days and have heard nothing for a week; same colour as `.closing-clash`. |
src/lastsent.test.ts +12
| @@ -36,3 +36,15 @@ test("nothing sent yet, then a declined draft still counts for nothing, then a s | ||
| 36 | 36 | expect(page()).toContain(`12 Oak Lane`); |
| 37 | 37 | expect(everyone().find((p) => p.email === "[email protected]")!.last_sent).toBeNull(); |
| 38 | 38 | }); |
| 39 | ||
| 40 | test("the sample data on a fresh boot flags at least one person on /people, escaped", async () => { | |
| 41 | const { refresh } = await import("./sample.ts"); | |
| 42 | const fresh = openDb(mkdtempSync(join(tmpdir(), "app-nudge-"))); | |
| 43 | refresh(fresh); | |
| 44 | const l = listDeals(fresh, alice); | |
| 45 | if (!l.ok) throw new Error(l.message); | |
| 46 | const on = today(DEFAULT_ZONE); | |
| 47 | const html = peoplePage({ who: alice, people: people(l.value, on), on }); | |
| 48 | expect(html).toContain('class="person-nudge"'); | |
| 49 | expect(html).toContain("Owes "); | |
| 50 | }); |
src/pages/people.ts +2 −1
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | import { relative, spoken } from "../dates.ts"; |
| 8 | 8 | import { escape } from "../http.ts"; |
| 9 | import type { Person } from "../people.ts"; | |
| 9 | import { nudgeLine, type Person } from "../people.ts"; | |
| 10 | 10 | import type { Who } from "../who.ts"; |
| 11 | 11 | import type { Agent } from "../reminders.ts"; |
| 12 | 12 | import { partyContact } from "./contact.ts"; |
| @@ -24,6 +24,7 @@ const lastHeard = (l: Person["last_sent"]): string => | ||
| 24 | 24 | const person = (p: Person, on: string): string => `<section class="card person"> |
| 25 | 25 | <h2>${escape(p.name)}</h2> |
| 26 | 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 | ${p.nudge === null ? "" : `<p class="person-nudge">${escape(nudgeLine(p.nudge, on))}</p>`} | |
| 27 | 28 | ${lastHeard(p.last_sent)} |
| 28 | 29 | ${p.owes.length === 0 ? `<p class="muted">Nothing open</p>` : `<ul class="week-list">${p.owes.map((o) => owedRow(o, on)).join("")}</ul>`} |
| 29 | 30 | </section>`; |
src/partycontact.test.ts +1 −1
| @@ -10,7 +10,7 @@ const contacts = ["[email protected]", "(555) 010-0142", "Ask at the front desk | ||
| 10 | 10 | |
| 11 | 11 | const bare = (h: string) => h.replace(/<p class="agent-contact">.*?<\/p>/, ""); |
| 12 | 12 | const peopleHtml = (contact: string) => bare( |
| 13 | peoplePage({ who, on: "2026-10-10", people: [{ name: "P", roles: ["Lender"], contact, email: "", phone: "", owes: [] } as unknown as Person] })); | |
| 13 | peoplePage({ who, on: "2026-10-10", people: [{ name: "P", roles: ["Lender"], contact, email: "", phone: "", owes: [], last_sent: null, nudge: null } as unknown as Person] })); | |
| 14 | 14 | const dealHtml = (contact: string) => bare( |
| 15 | 15 | dealPage({ |
| 16 | 16 | who, |
src/people.test.ts +35 −1
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { expect, test } from "bun:test"; |
| 2 | 2 | import type { DealView } from "./deals.ts"; |
| 3 | import { people, personKey } from "./people.ts"; | |
| 3 | import { nudgeLine, people, personKey } from "./people.ts"; | |
| 4 | 4 | |
| 5 | 5 | const on = "2026-10-10"; |
| 6 | 6 | const deal = (id: number, address: string, parties: [number, string, string, string][], dates: [number, string, string, string, string | null][], closed = false): DealView => |
| @@ -57,3 +57,37 @@ test("last_sent: nothing sent is null; the newest sent message across deals wins | ||
| 57 | 57 | expect(all.find((p) => p.contact === "[email protected]")!.last_sent).toBeNull(); |
| 58 | 58 | expect(people([a], on).find((p) => p.contact === "[email protected]")!.last_sent?.sent_on).toBe("2026-11-06"); |
| 59 | 59 | }); |
| 60 | ||
| 61 | // The nudge: owes an open date due within three days, and nothing sent for over a week. | |
| 62 | const nudgeDeal = (due: string, extra: { done_at?: string | null; waived_at?: string | null } = {}, sentOn?: string): DealView => | |
| 63 | ({ | |
| 64 | id: 1, address: "1418 Alder Lane", closed: false, | |
| 65 | sent: sentOn === undefined ? [] : [{ id: 1, deal_id: 1, party_id: 1, label: "Hello", sent_at: `${sentOn}T10:00:00Z`, sent_on: sentOn }], | |
| 66 | parties: [{ id: 1, deal_id: 1, role: "lender", name: "Priya", contact: "[email protected]", email: "[email protected]", phone: "" }], | |
| 67 | deadlines: [{ id: 1, owes: "lender", label: "Financing", due, done_at: extra.done_at ?? null, waived_at: extra.waived_at ?? null }], | |
| 68 | }) as unknown as DealView; | |
| 69 | const nudged = (due: string, sentOn?: string, extra = {}) => people([nudgeDeal(due, extra, sentOn)], "2026-10-10")[0]!.nudge; | |
| 70 | ||
| 71 | test("due in 3 days and last sent 8 days ago is flagged, in words", () => { | |
| 72 | const n = nudged("2026-10-13", "2026-10-02")!; | |
| 73 | expect(n.quiet_days).toBe(8); | |
| 74 | expect(nudgeLine(n, "2026-10-10")).toBe("Owes Financing on 1418 Alder Lane in 3 days · nothing sent in 8 days"); | |
| 75 | expect(nudgeLine(nudged("2026-10-12")!, "2026-10-10")).toBe("Owes Financing on 1418 Alder Lane in 2 days · nothing sent yet"); | |
| 76 | }); | |
| 77 | ||
| 78 | test("last sent 6 or 7 days ago, due in 4 days, overdue, done or waived is not flagged", () => { | |
| 79 | expect(nudged("2026-10-13", "2026-10-04")).toBeNull(); | |
| 80 | expect(nudged("2026-10-13", "2026-10-03")).toBeNull(); | |
| 81 | expect(nudged("2026-10-14")).toBeNull(); | |
| 82 | expect(nudged("2026-10-09")).toBeNull(); | |
| 83 | expect(nudged("2026-10-11", undefined, { done_at: "2026-10-09T10:00:00Z" })).toBeNull(); | |
| 84 | expect(nudged("2026-10-11", undefined, { waived_at: "2026-10-09T10:00:00Z" })).toBeNull(); | |
| 85 | expect(nudged("2026-10-10")).not.toBeNull(); | |
| 86 | }); | |
| 87 | ||
| 88 | test("flagged people come first, soonest date first; the rest keep their order", () => { | |
| 89 | const a = nudgeDeal("2026-10-13"), b = nudgeDeal("2026-10-11"); | |
| 90 | const mk = (d: DealView, id: number, name: string, email: string) => ({ ...d, id, parties: [{ ...d.parties[0]!, id, deal_id: id, name, email, contact: email }], deadlines: d.deadlines.map((x) => ({ ...x, id })) }) as unknown as DealView; | |
| 91 | const calm = deal(9, "Z", [[20, "buyer", "Aaron", "aaron"]], [[20, "buyer", "Offer", "2026-10-30", null]]); | |
| 92 | expect(people([calm, mk(a, 2, "Late", "l@x"), mk(b, 3, "Early", "e@x")], "2026-10-10").map((p) => p.name)).toEqual(["Early", "Late", "Aaron"]); | |
| 93 | }); |
src/people.ts +43 −10
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * Plain data from deals and a day; the page, the API and the MCP tool share it. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { urgency, type Urgency } from "./dates.ts"; | |
| 7 | import { daysBetween, relative, urgency, type Urgency } from "./dates.ts"; | |
| 8 | 8 | import type { DealView, Party } from "./deals.ts"; |
| 9 | 9 | import { isOpen, PARTY_LABEL, type PartyRole } from "./deadlines.ts"; |
| 10 | 10 | |
| @@ -40,8 +40,34 @@ export interface Person { | ||
| 40 | 40 | readonly owes: readonly Owed[]; |
| 41 | 41 | /** Their most recent sent reminder or notice across deals; null when none was sent. */ |
| 42 | 42 | readonly last_sent: LastSent | null; |
| 43 | /** Set when they owe a date within three days and have heard nothing for over a week. */ | |
| 44 | readonly nudge: Nudge | null; | |
| 43 | 45 | } |
| 44 | 46 | |
| 47 | /** A person to chase: the soonest open date they owe within three days, and how long since the agent last sent them anything. */ | |
| 48 | export interface Nudge { | |
| 49 | readonly owed: Owed; | |
| 50 | /** Whole days since the last sent message; null when none was ever sent. */ | |
| 51 | readonly quiet_days: number | null; | |
| 52 | } | |
| 53 | ||
| 54 | const NUDGE_WITHIN_DAYS = 3; | |
| 55 | const NUDGE_QUIET_DAYS = 7; | |
| 56 | ||
| 57 | /** Whether this person needs a nudge on day `on`: owes an open date due today or within three days, and the last sent message is over seven days old or absent. Never reads the clock. */ | |
| 58 | export function nudgeFor(owes: readonly Owed[], last: LastSent | null, on: string): Nudge | null { | |
| 59 | const owed = owes | |
| 60 | .filter((o) => { const n = daysBetween(on, o.due); return n >= 0 && n <= NUDGE_WITHIN_DAYS; }) | |
| 61 | .sort((a, b) => a.due.localeCompare(b.due) || a.address.localeCompare(b.address))[0]; | |
| 62 | if (owed === undefined) return null; | |
| 63 | const quiet = last === null ? null : daysBetween(last.sent_on, on); | |
| 64 | return quiet !== null && quiet <= NUDGE_QUIET_DAYS ? null : { owed, quiet_days: quiet }; | |
| 65 | } | |
| 66 | ||
| 67 | /** The amber line: "Owes Financing on 1418 Alder Lane in 2 days · nothing sent in 9 days". */ | |
| 68 | export const nudgeLine = (n: Nudge, on: string): string => | |
| 69 | `Owes ${n.owed.label} on ${n.owed.address} ${relative(n.owed.due, on)} · ${n.quiet_days === null ? "nothing sent yet" : `nothing sent in ${n.quiet_days} days`}`; | |
| 70 | ||
| 45 | 71 | /** What identifies a party: their email and phone, ignoring case and outer spaces; with neither, their contact, else their name. */ |
| 46 | 72 | export const personKeys = (p: { name: string; contact: string; email?: string; phone?: string }): string[] => { |
| 47 | 73 | const t = (v: string | undefined) => (v ?? "").trim().toLowerCase(); |
| @@ -113,16 +139,23 @@ export function people(deals: readonly DealView[], on: string): Person[] { | ||
| 113 | 139 | } |
| 114 | 140 | } |
| 115 | 141 | return [...new Set(byKey.values())] |
| 116 | .map((p) => ({ | |
| 117 | name: p.name, | |
| 118 | contact: p.contact, | |
| 119 | email: p.email, | |
| 120 | phone: p.phone, | |
| 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 }, | |
| 123 | owes: [...p.owes.values()].sort((a, b) => a.due.localeCompare(b.due) || a.address.localeCompare(b.address)), | |
| 124 | })) | |
| 142 | .map((p) => { | |
| 143 | const owes = [...p.owes.values()].sort((a, b) => a.due.localeCompare(b.due) || a.address.localeCompare(b.address)); | |
| 144 | const 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 }; | |
| 145 | return { | |
| 146 | name: p.name, | |
| 147 | contact: p.contact, | |
| 148 | email: p.email, | |
| 149 | phone: p.phone, | |
| 150 | roles: [...p.roles].map((r) => PARTY_LABEL[r]), | |
| 151 | last_sent, | |
| 152 | owes, | |
| 153 | nudge: nudgeFor(owes, last_sent, on), | |
| 154 | }; | |
| 155 | }) | |
| 125 | 156 | .sort((a, b) => { |
| 157 | if ((a.nudge === null) !== (b.nudge === null)) return a.nudge === null ? 1 : -1; | |
| 158 | if (a.nudge && b.nudge) return a.nudge.owed.due.localeCompare(b.nudge.owed.due) || a.name.localeCompare(b.name); | |
| 126 | 159 | if ((a.owes.length === 0) !== (b.owes.length === 0)) return a.owes.length === 0 ? 1 : -1; |
| 127 | 160 | return (a.owes[0]?.due ?? "").localeCompare(b.owes[0]?.due ?? "") || a.name.localeCompare(b.name); |
| 128 | 161 | }); |
src/terminal.ts +2 −1
| @@ -83,7 +83,7 @@ import { drafts, heldFrom, inClockOrder, momentLabel, pending, remindsLine, sent | ||
| 83 | 83 | import type { AuditRow } from "./audit.ts"; |
| 84 | 84 | import type { Result } from "./result.ts"; |
| 85 | 85 | import type { Who } from "./who.ts"; |
| 86 | import { people } from "./people.ts"; | |
| 86 | import { nudgeLine, people } from "./people.ts"; | |
| 87 | 87 | import { reachedAt } from "./outbox.ts"; |
| 88 | 88 | import { addresses, refusal, when, wording } from "./activity.ts"; |
| 89 | 89 | import { listAudit } from "./actions.ts"; |
| @@ -821,6 +821,7 @@ export function terminal( | ||
| 821 | 821 | if (all.length === 0) lines.push(dim("No one yet: add a deal and its parties.")); |
| 822 | 822 | for (const p of all) { |
| 823 | 823 | lines.push(`${bold(p.name)} ${dim(`${p.roles.join(", ")}${reachedAt(p) === "" ? "" : ` · ${reachedAt(p)}`}`)}`); |
| 824 | if (p.nudge !== null) lines.push(` ${tint("soon", nudgeLine(p.nudge, day))}`); | |
| 824 | 825 | 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}`)); |
| 825 | 826 | if (p.owes.length === 0) lines.push(dim(" Nothing open")); |
| 826 | 827 | for (const o of p.owes) |
static/app.css +4
| @@ -932,6 +932,10 @@ a.marker { | ||
| 932 | 932 | margin: var() 0; |
| 933 | 933 | color: var(); |
| 934 | 934 | } |
| 935 | .person-nudge { | |
| 936 | margin: var() 0; | |
| 937 | color: var(); | |
| 938 | } | |
| 935 | 939 | .closing-clash a { |
| 936 | 940 | color: inherit; |
| 937 | 941 | } |
new above
offline