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

The README's "What is real, and what is not yet" names what the app does today, so a realtor reading it before the meeting is not surprised #208

Parked opened this
Closed without merging

mason/deal-clock:mason/191-the-readme-s-what-is-real-and-what-is-no → main 5 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
19 files changed +395 −27
README.md +25 −3
@@ -104,7 +104,7 @@ you already have), fix a typo with Edit, add a date the contract added (an HOA
104104 review), waive a contingency the buyer gave up, change who owes a date, correct
105105 the address, and set the closing time and place. If two of your open deals close the same day less than two hours apart,
106106 an amber "Also closing at 2:30 pm" line names the other deal on This week, on
107 both deals' pages and in the terminal's deal view. An Inspection or Final
107 both deals' pages and in the terminal's deal view; an inspection, walkthrough or closing less than two hours from another of your timed appointments that day gets an "Also at 10:00 am: Inspection, 12 Elm St" line the same way. An Inspection or Final
108108 walkthrough row has **Set time and place** too (a time on a quarter hour and
109109 one line for where, either optional; clear both to remove them): the buyer
110110 sees them beside the date on the client timeline, your calendar file gives
@@ -143,7 +143,9 @@ An admin sees **Activity** in the header: the newest hundred things anyone
143143 tried to change, one plain line each (who, what, on which deal, when, and why
144144 it was refused if it was). **Messages** narrows it to sends, declines and
145145 undos, so the sales meeting can show that every message that went out was
146 approved by a named person at a stated time. Anyone else is told no.
146 approved by a named person at a stated time. **Download spreadsheet** on that
147 page saves the same lines (or just the messages) as a file that opens in Excel
148 or Numbers. Anyone else is told no.
147149
148150 ## Spreadsheets and calendar
149151
@@ -187,7 +189,27 @@ return as they were, dated from today, and the deals you opened are left alone.
187189 - **Real:** the dates and their math, mark done, moves with their reasons,
188190 who owes what, the reminder drafts and editing them, the record of what was
189191 sent, the reasons for messages you chose not to send, the calendar file, and
190 adding parties, dates and deals.
192 adding parties, dates and deals (see [opening and shaping a
193 deal](#opening-and-shaping-a-deal)).
194 - **Real:** you can download all your deals as one file and bring them back
195 later, on this app or another account; the record of messages is saved but not
196 brought back ([make it yours](#make-it-yours)).
197 - **Real:** an inspection, final walkthrough or closing can carry a time and a
198 place, which show on the client timeline, in your calendar file and in the
199 reminder ([opening and shaping a deal](#opening-and-shaping-a-deal)).
200 - **Real:** two closings, or an inspection or walkthrough and another of your
201 timed appointments, on the same day less than two hours apart are flagged
202 on both deals' pages ([opening and shaping a
203 deal](#opening-and-shaping-a-deal)).
204 - **Real:** a month after closing a "How is the new home?" note, and a year
205 after a "Happy home anniversary" note, are drafted and wait for your approval
206 ([opening and shaping a deal](#opening-and-shaping-a-deal)).
207 - **Real:** an admin can read the Activity record of who tried to change what,
208 and download it as a spreadsheet ([Activity](#activity)).
209 - **Real:** price, earnest money and commission rate on a deal, the commission
210 pending and earned this year under the clock, and a broker file to print
211 ([commission and your year](#commission-and-your-year)); spreadsheets of your
212 deals ([spreadsheets and calendar](#spreadsheets-and-calendar)).
191213 - **Real:** the clock, a deal page and the client timeline answer in under 50
192214 ms with 200 deals.
193215 - **Real:** every page is checked for keyboard and screen-reader use.
contract/openapi.json +64
@@ -1211,6 +1211,38 @@
12111211 "format": "date"
12121212 }
12131213 }
1214 },
1215 "clashes": {
1216 "type": "array",
1217 "description": "Other timed open inspections, walkthroughs or closings of this agent the same day, less than two hours from this timed date. Empty when none.",
1218 "items": {
1219 "type": "object",
1220 "properties": {
1221 "dealId": {
1222 "type": "integer"
1223 },
1224 "address": {
1225 "type": "string"
1226 },
1227 "label": {
1228 "type": "string"
1229 },
1230 "time": {
1231 "type": [
1232 "string",
1233 "null"
1234 ],
1235 "pattern": "^(0[7-9]|1[0-9]):(00|15|30|45)$|^20:00$",
1236 "description": "When it closes, HH:MM on a quarter hour from 07:00 to 20:00, local time; null while none is set."
1237 }
1238 },
1239 "required": [
1240 "dealId",
1241 "address",
1242 "label",
1243 "time"
1244 ]
1245 }
12141246 }
12151247 }
12161248 }
@@ -3422,6 +3454,38 @@
34223454 "format": "date"
34233455 }
34243456 }
3457 },
3458 "clashes": {
3459 "type": "array",
3460 "description": "Other timed open inspections, walkthroughs or closings of this agent the same day, less than two hours from this timed date. Empty when none.",
3461 "items": {
3462 "type": "object",
3463 "properties": {
3464 "dealId": {
3465 "type": "integer"
3466 },
3467 "address": {
3468 "type": "string"
3469 },
3470 "label": {
3471 "type": "string"
3472 },
3473 "time": {
3474 "type": [
3475 "string",
3476 "null"
3477 ],
3478 "pattern": "^(0[7-9]|1[0-9]):(00|15|30|45)$|^20:00$",
3479 "description": "When it closes, HH:MM on a quarter hour from 07:00 to 20:00, local time; null while none is set."
3480 }
3481 },
3482 "required": [
3483 "dealId",
3484 "address",
3485 "label",
3486 "time"
3487 ]
3488 }
34253489 }
34263490 }
34273491 }
docs/TECHNICAL.md +2
@@ -365,6 +365,8 @@ The forge sets `PORT`, `FORGE_APP_DATA`, `FORGE_APP_ENV` (`production` or
365365
366366 `closingConflicts` on a deal (`GET /api/deals/:id` and the list) lists the agent's other open deals closing the same day, both with a time set, less than two hours apart: `{dealId, address, closing_time}`. `src/overlap.ts` computes it in memory over the deals already loaded; it is empty for a closed or fallen-through deal, a deal with no time, and deals of another agent.
367367
368 Each date in a deal's `deadlines` carries `clashes`: the agent's other open, timed inspections, walkthroughs and closings the same day, less than two hours from this date's own time (`{dealId, address, label, time}`, label being Inspection, Walkthrough or Closing). Only pairs with at least one inspection or walkthrough appear here; two closings stay in `closingConflicts`. `appointmentClashes` in `src/overlap.ts` computes it over the deals already loaded.
369
368370 `deal.closing_time` (`HH:MM`, a quarter hour, 07:00 to 20:00) and `deal.closing_place` (1 to 200
369371 characters) are nullable columns, read and written as `closing_time` and `closing_place` by
370372 `GET`/`PATCH /api/deals/:id`, the `update_closing` tool and `POST /deals/:id/closing`; `src/closing.ts`
src/clash.test.ts added +102
@@ -0,0 +1,102 @@
1 /** An inspection or walkthrough less than two hours from another timed appointment or closing of the agent's: flagged, escaped, linked. */
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 { openDb } from "./db.ts";
7 import { createDeal, getDeal, listDeals, markDone, setAppointment } from "./deals.ts";
8 import { appointmentClashes } from "./overlap.ts";
9 import { dealPage } from "./pages/deal.ts";
10 import { weekCard } from "./pages/clock.ts";
11 import { weekPage } from "./pages/week.ts";
12 import type { Who } from "./who.ts";
13
14 type D = { id: number; kind: string; label: string; due: string; time: string | null; done_at: string | null; waived_at: string | null };
15 const date = (id: number, kind: string, time: string | null, over: Partial<D> = {}): D => ({ id, kind, label: "Inspection period ends", due: "2026-11-20", time, done_at: null, waived_at: null, ...over });
16 const deal = (id: number, deadlines: D[], over: Record<string, unknown> = {}) => ({
17 id, address: `${id} Way`, author_id: "u1", closing: "2026-11-30", closing_time: null, closed: false, fell_through: false, deadlines, ...over,
18 });
19 const ids = (m: Map<number, { dealId: number }[]>, k: number) => m.get(k)?.map((c) => c.dealId);
20
21 test("inspection vs inspection: 90 minutes flagged, two hours not", () => {
22 const got = appointmentClashes([deal(1, [date(11, "inspection", "10:00")]), deal(2, [date(21, "inspection", "11:30")])]);
23 expect(ids(got, 11)).toEqual([2]);
24 expect(ids(got, 21)).toEqual([1]);
25 expect(appointmentClashes([deal(1, [date(11, "inspection", "10:00")]), deal(2, [date(21, "inspection", "12:00")])]).size).toBe(0);
26 });
27
28 test("an inspection against a closing the same day is flagged both ways; two closings are left to closingConflicts", () => {
29 const closing = date(31, "closing", null, { label: "Closing", due: "2026-11-20" });
30 const got = appointmentClashes([deal(1, [date(11, "walkthrough", "09:00")]), deal(3, [closing], { closing: "2026-11-20", closing_time: "10:00" })]);
31 expect(ids(got, 11)).toEqual([3]);
32 expect(got.get(11)?.[0]).toMatchObject({ label: "Closing", time: "10:00" });
33 expect(ids(got, 31)).toEqual([1]);
34 const two = appointmentClashes([deal(3, [closing], { closing: "2026-11-20", closing_time: "10:00" }), deal(4, [{ ...closing, id: 41 }], { closing: "2026-11-20", closing_time: "10:30" })]);
35 expect(two.size).toBe(0);
36 });
37
38 test("done, waived, untimed, other-day, closed, fallen and another agent's dates are not compared", () => {
39 const base = deal(1, [date(11, "inspection", "10:00")]);
40 const against = (d: D, over: Record<string, unknown> = {}) => appointmentClashes([base, deal(2, [d], over)]).size;
41 expect(against(date(21, "inspection", "10:30"))).toBe(2);
42 expect(against(date(21, "inspection", "10:30", { done_at: "2026-11-20T10:00:00Z" }))).toBe(0);
43 expect(against(date(21, "inspection", "10:30", { waived_at: "2026-11-19T10:00:00Z" }))).toBe(0);
44 expect(against(date(21, "inspection", null))).toBe(0);
45 expect(against(date(21, "inspection", "10:30", { due: "2026-11-21" }))).toBe(0);
46 expect(against(date(21, "inspection", "10:30"), { closed: true })).toBe(0);
47 expect(against(date(21, "inspection", "10:30"), { fell_through: true })).toBe(0);
48 expect(against(date(21, "inspection", "10:30"), { author_id: "u2" })).toBe(0);
49 });
50
51 const db = openDb(mkdtempSync(join(tmpdir(), "app-clash-")));
52 const alice: Who = { role: "user", id: "u1", name: "alice" };
53 const bob: Who = { role: "user", id: "u2", name: "bob" };
54 const agent = { name: "Dana", brokerage: "Harbor", phone: "555", email: "[email protected]" };
55 const open = (who: Who, address: string) => {
56 const made = createDeal(db, who, { address, buyer: "Ann Buyer", seller: "Sam Seller", contractDate: "2026-10-01", closingDate: "2026-11-30", openAnyway: true });
57 if (!made.ok) throw new Error(made.message);
58 return made.value;
59 };
60 const all = (who: Who) => { const l = listDeals(db, who); if (!l.ok) throw new Error(l.message); return l.value; };
61 const inspection = (d: { deadlines: readonly { id: number; kind: string }[] }) => d.deadlines.find((x) => x.kind === "inspection")!;
62
63 test("the week, the deal page and the read show the clash, escaped and linked, and another agent's never", () => {
64 const a = open(alice, "1 <script>x</script> Way");
65 const b = open(alice, "2 Quiet Way");
66 const c = open(bob, "3 Bob Way");
67 const set = (who: Who, deal: { id: number; deadlines: readonly { id: number; kind: string }[] }, time: string) => {
68 const r = setAppointment(db, who, { id: inspection(deal).id, time, place: "" });
69 if (!r.ok) throw new Error(r.message);
70 };
71 const dueA = all(alice).find((d) => d.id === a.id)!.deadlines.find((d) => d.kind === "inspection")!.due;
72 // Align the two inspections on one day, as the standard schedule may differ.
73 for (const d of [b, c]) {
74 const x = all(d === c ? bob : alice).find((v) => v.id === d.id)!;
75 db.query("UPDATE deadline SET due = ?1 WHERE id = ?2").run(dueA, inspection(x).id);
76 }
77 set(alice, a, "10:00");
78 set(alice, b, "11:30");
79 set(bob, c, "10:30");
80
81 const mine = all(alice);
82 const first = mine.find((d) => d.id === a.id)!;
83 expect(inspection(first)).toMatchObject({ clashes: [{ dealId: b.id, address: "2 Quiet Way", label: "Inspection", time: "11:30" }] });
84 expect(inspection(mine.find((d) => d.id === c.id)!)).toMatchObject({ clashes: [] });
85
86 const sheet = weekPage({ who: alice, agent, deals: mine, on: dueA });
87 expect(sheet).toContain(`Also at 11:30 am: Inspection, <a href="/deals/${b.id}">2 Quiet Way</a>`);
88 expect(weekCard(mine, dueA)).toContain("Also at 10:00 am: Inspection, 1 &lt;script&gt;x&lt;/script&gt; Way");
89 expect(weekCard(mine, dueA)).not.toContain("<script>x");
90
91 const got = getDeal(db, alice, { id: b.id });
92 if (!got.ok) throw new Error(got.message);
93 const page = dealPage({ who: alice, deal: got.value, agent, on: dueA });
94 expect(page).toContain(`Also at 10:00 am: Inspection, <a href="/deals/${a.id}">1 &lt;script&gt;x&lt;/script&gt; Way</a>`);
95 expect(page).not.toContain("<script>x");
96
97 // Done or waived clears it.
98 const done = markDone(db, alice, { id: inspection(first).id, done: true });
99 expect(done.ok).toBe(true);
100 const after = getDeal(db, alice, { id: b.id });
101 expect(after.ok && inspection(after.value)).toMatchObject({ clashes: [] });
102 });
src/deals.ts +18 −6
@@ -40,7 +40,7 @@ import { outboxes } from "./outbox.ts";
4040 import { conflictLine, conflicts, type Conflict } from "./order.ts";
4141 import { SEND_SPAN, draftOfMoment, statusDrafts, type Agent, type Draft } from "./reminders.ts";
4242 import { audited, conflict, fail, ok, refuse, type Result } from "./result.ts";
43 import { closingConflicts, type ClosingConflict } from "./overlap.ts";
43 import { appointmentClashes, closingConflicts, type Clash, type ClosingConflict } from "./overlap.ts";
4444 import type { Who } from "./who.ts";
4545
4646 export interface Deal {
@@ -188,6 +188,8 @@ export interface DeadlineView extends Omit<Deadline, "owes_from" | "owes_by" | "
188188 readonly moves: readonly Move[];
189189 /** An open date due on a weekend or US federal holiday: the business day it rolls to. Null otherwise. */
190190 readonly nonBusinessDay: { readonly next: string } | null;
191 /** Other timed appointments or closings of this agent the same day, less than two hours from this timed one; empty when none. */
192 readonly clashes: readonly Clash[];
191193 }
192194 /** The day the Closing date was marked done, by the app's own calendar (the one `today()` keeps). */
193195 export const closedOn = (deal: { zone: string; deadlines: readonly { kind: Kind; done_at: string | null }[]; closing: string }): string => {
@@ -308,6 +310,7 @@ function assemble(deal: Deal, rows: Children, zone: string): DealView {
308310 owes_changed: owes_from === null || owes_by === null || owes_on === null ? null : { from: owes_from, by: owes_by, on: owes_on },
309311 moves: moves.filter((m) => m.deadline_id === d.id),
310312 nonBusinessDay: isOpen(d) && !isBusinessDay(d.due) ? { next: nextBusinessDay(d.due) } : null,
313 clashes: [],
311314 })),
312315 sent: rows.sent.map((m) => withHref(m, rows.parties, zone)),
313316 declined: rows.declined,
@@ -319,9 +322,19 @@ function assemble(deal: Deal, rows: Children, zone: string): DealView {
319322
320323 /** The deal with the closings of its agent's other deals it overlaps; one read, and only for a timed, open closing. */
321324 function withClosingConflicts(db: Database, deal: DealView): DealView {
322 if (deal.closing_time === null || deal.closed || deal.fell_through) return deal;
325 if (deal.closed || deal.fell_through) return deal;
326 if (deal.closing_time === null && !deal.deadlines.some((d) => d.time !== null)) return deal;
323327 const peers = viewMany(db, " WHERE author_id = ?1", [deal.author_id]);
324 return { ...deal, closingConflicts: closingConflicts(peers).get(deal.id) ?? [] };
328 return withClashes([deal], closingConflicts(peers), appointmentClashes(peers))[0]!;
329 }
330
331 /** The deals with the closing conflicts and the appointment clashes read off the loaded set. */
332 function withClashes(deals: readonly DealView[], closings: Map<number, ClosingConflict[]>, clashes: Map<number, Clash[]>): DealView[] {
333 return deals.map((d) => ({
334 ...d,
335 closingConflicts: closings.get(d.id) ?? [],
336 deadlines: d.deadlines.map((x) => (clashes.has(x.id) ? { ...x, clashes: clashes.get(x.id)! } : x)),
337 }));
325338 }
326339
327340 function view(db: Database, deal: Deal): DealView {
@@ -447,10 +460,9 @@ export function listDeals(db: Database, who: Who): Result<DealView[]> {
447460 ` WHERE ${may.where.map((c) => `${c} = ?1`).join(" OR ")}`,
448461 [who.role === "anon" ? "" : who.id],
449462 );
450 const clashes = closingConflicts(deals);
451463 return ok(
452 deals
453 .map((d) => shown(who, { ...d, closingConflicts: clashes.get(d.id) ?? [] }))
464 withClashes(deals, closingConflicts(deals), appointmentClashes(deals))
465 .map((d) => shown(who, d))
454466 .sort((a, b) => a.closing.localeCompare(b.closing) || a.id - b.id),
455467 );
456468 }
src/order.page.test.ts +3
@@ -29,6 +29,9 @@ test("on a fresh boot only 9 Orchard Row is flagged, for its listing expiring be
2929 expect(deal.conflicts.map((c) => c.label)).toEqual(deal.address === "9 Orchard Row" ? ["Listing agreement expires"] : []);
3030 const page = await (await fetch(`${base}/`, { headers: alice })).text();
3131 expect(page).toContain("1 out of order");
32 const label = page.match(/aria-label="(Listing agreement expires[^"]*)"/)![1]!;
33 expect(label).toContain("closing falls after the listing agreement expires");
34 expect(label).not.toContain("falls on or after closing");
3235 });
3336
3437 test("moving Alder Lane's financing past closing succeeds and shows the flag everywhere", async () => {
src/order.test.ts +11 −1
@@ -1,5 +1,6 @@
11 import { expect, test } from "bun:test";
2 import { conflictLine, conflicts } from "./order.ts";
2 import { conflictLine, conflictShort, conflicts } from "./order.ts";
3 import { LISTING_EXPIRES } from "./deadlines.ts";
34
45 const d = (id: number, kind: string, due: string, done_at: string | null = null) => ({
56 id,
@@ -33,3 +34,12 @@ test("the line says it in words", () => {
3334 expect(conflictLine(c)).toBe("Financing (Nov 24) now falls after closing (Nov 20): move one or the other.");
3435 expect(conflictLine({ ...c, due: "2026-11-20" })).toContain("now falls on closing");
3536 });
37
38 test("the marker's short words: the listing's own, or on or after closing", () => {
39 const listing = { deadline_id: 1, label: LISTING_EXPIRES, due: "2026-11-30", closing: "2026-12-03" };
40 expect(conflictShort(listing)).toBe("closing falls after the listing agreement expires");
41 expect(conflictShort({ ...listing, due: "2026-12-03" })).toBe("closing falls on the day the listing agreement expires");
42 const late = { deadline_id: 2, label: "Financing", due: "2026-11-24", closing: "2026-11-20" };
43 expect(conflictShort(late)).toBe("falls on or after closing");
44 expect(conflictShort({ ...late, due: "2026-11-20" })).toBe("falls on or after closing");
45 });
src/order.ts +4
@@ -41,3 +41,7 @@ export const conflictLine = (c: Conflict): string =>
4141 c.label === LISTING_EXPIRES
4242 ? `Closing (${short(c.closing)}) falls ${c.due === c.closing ? "on the day" : "after"} the listing agreement expires (${short(c.due)}): extend the listing or move closing.`
4343 : `${c.label} (${short(c.due)}) now falls ${c.due === c.closing ? "on" : "after"} closing (${short(c.closing)}): move one or the other.`;
44
45 /** The conflict in a few words, for a marker's spoken label: "closing falls after the listing agreement expires"; otherwise "falls on or after closing". */
46 export const conflictShort = (c: Conflict): string =>
47 c.label === LISTING_EXPIRES ? `closing falls ${c.due === c.closing ? "on the day" : "after"} the listing agreement expires` : "falls on or after closing";
src/overlap.ts +88
@@ -6,7 +6,9 @@
66 */
77
88 import { clock12 } from "./closing.ts";
9 import { isOpen } from "./deadlines.ts";
910 import { escape } from "./http.ts";
11 import { isAppointment } from "./appointment.ts";
1012
1113 /** Two closings closer than this many minutes cannot both be kept. */
1214 export const APART = 120;
@@ -62,3 +64,89 @@ export function clashLine(conflicts: readonly ClosingConflict[], tag: "p" | "sma
6264 const links = conflicts.map((c) => (linked ? `<a href="/deals/${c.dealId}">${escape(c.address)}</a>` : escape(c.address))).join(", ");
6365 return `<${tag} class="closing-clash">Also closing at ${escape(clock12(first.closing_time))}: ${links}</${tag}>`;
6466 }
67
68 /** Another timed date of the same agent (label is the kind: Inspection, Walkthrough or Closing), the same day, less than `APART` minutes from this one. */
69 export interface Clash {
70 readonly dealId: number;
71 readonly address: string;
72 readonly label: string;
73 readonly time: string;
74 }
75
76 interface Booked {
77 readonly id: number;
78 readonly address: string;
79 readonly author_id: string;
80 readonly closing: string;
81 readonly closing_time: string | null;
82 readonly closed: boolean;
83 readonly fell_through: boolean;
84 readonly deadlines: readonly {
85 readonly id: number;
86 readonly kind: string;
87 readonly label: string;
88 readonly due: string;
89 readonly time: string | null;
90 readonly done_at: string | null;
91 readonly waived_at: string | null;
92 }[];
93 }
94
95 interface Slot {
96 readonly deadlineId: number;
97 readonly dealId: number;
98 readonly address: string;
99 readonly label: string;
100 readonly kind: string;
101 readonly day: string;
102 readonly time: string;
103 readonly author: string;
104 }
105
106 /**
107 * For each deadline id that has one, the other timed appointments or closings of the
108 * same agent the same day, less than `APART` minutes away. Only pairs with at least
109 * one inspection or walkthrough: two closings are `closingConflicts`. Done, waived,
110 * untimed dates and closed or fallen-through deals are never compared.
111 */
112 export function appointmentClashes(deals: readonly Booked[]): Map<number, Clash[]> {
113 const byDay = new Map<string, Slot[]>();
114 for (const deal of deals) {
115 if (deal.closed || deal.fell_through) continue;
116 for (const d of deal.deadlines) {
117 const closing = d.kind === "closing";
118 const time = closing ? deal.closing_time : d.time;
119 if (time === null || !(closing || isAppointment(d.kind)) || !isOpen(d)) continue;
120 const day = closing ? deal.closing : d.due;
121 const key = `${deal.author_id}|${day}`;
122 const slot: Slot = { deadlineId: d.id, dealId: deal.id, address: deal.address, label: d.kind[0]!.toUpperCase() + d.kind.slice(1), kind: d.kind, day, time, author: deal.author_id };
123 byDay.set(key, [...(byDay.get(key) ?? []), slot]);
124 }
125 }
126 const out = new Map<number, Clash[]>();
127 for (const slots of byDay.values()) {
128 for (const a of slots) {
129 const near = slots
130 .filter((b) => b.deadlineId !== a.deadlineId && (a.kind !== "closing" || b.kind !== "closing") && Math.abs(minutes(b.time) - minutes(a.time)) < APART)
131 .sort((x, y) => x.time.localeCompare(y.time) || x.deadlineId - y.deadlineId)
132 .map((b) => ({ dealId: b.dealId, address: b.address, label: b.label, time: b.time }));
133 if (near.length > 0) out.set(a.deadlineId, near);
134 }
135 }
136 return out;
137 }
138
139 /** "Also at 10:00 am: Inspection, 12 Elm St" as plain text, for the terminal; "" for none. */
140 export function clashesText(clashes: readonly Clash[]): string {
141 return clashes.map((c, i) => `${i === 0 ? "Also" : "also"} at ${clock12(c.time)}: ${c.label}, ${c.address}`).join("; ");
142 }
143
144 /** "Also at 10:00 am: Inspection, 12 Elm St", each address linked to its deal; "" for none. */
145 export function clashesLine(clashes: readonly Clash[], tag: "p" | "small" = "p", linked = true): string {
146 if (clashes.length === 0) return "";
147 const items = clashes.map((c, i) => {
148 const where = linked ? `<a href="/deals/${c.dealId}">${escape(c.address)}</a>` : escape(c.address);
149 return `${i === 0 ? "Also" : "also"} at ${escape(clock12(c.time))}: ${escape(c.label)}, ${where}`;
150 });
151 return `<${tag} class="closing-clash">${items.join("; ")}</${tag}>`;
152 }
src/pages/appointment.ts +2 −1
@@ -3,6 +3,7 @@
33 * that says them and the small form that sets them. Escaped here, once.
44 */
55
6 import { clashesLine } from "../overlap.ts";
67 import { appointmentLine, isAppointment } from "../appointment.ts";
78 import type { DeadlineView } from "../deals.ts";
89 import { escape } from "../http.ts";
@@ -17,7 +18,7 @@ export interface AppointmentProblem {
1718
1819 /** "10:00 am · 12 Elm St" under the date; nothing when unset or when the date is no appointment. */
1920 export const appointmentText = (d: DeadlineView): string =>
20 appointmentLine(d) === "" ? "" : `<p class="small appointment"><b>${escape(appointmentLine(d))}</b></p>`;
21 (appointmentLine(d) === "" ? "" : `<p class="small appointment"><b>${escape(appointmentLine(d))}</b></p>`) + clashesLine(d.clashes);
2122
2223 /** "Set time and place" for an inspection or a walkthrough; the form stays open, with the agent's text, when it was refused. */
2324 export function appointmentForm(d: DeadlineView, to: string, problem: AppointmentProblem | undefined): string {
src/pages/clock.ts +6 −5
@@ -12,8 +12,9 @@ import { escape } from "../http.ts";
1212 import { agent as defaults } from "../env.ts";
1313 import { todaysDrafts, unsent, type Agent } from "../reminders.ts";
1414 import type { Who } from "../who.ts";
15 import { clashLine } from "../overlap.ts";
16 import { byDay, closingNote, thisWeek } from "../week.ts";
15 import { conflictShort } from "../order.ts";
16 import { clashLine, clashesLine } from "../overlap.ts";
17 import { byDay, thisWeek, whereNote } from "../week.ts";
1718 import { layout } from "./layout.ts";
1819 import { mayRestore } from "../actions.ts";
1920 import { badge, draftLink, opens, owedBy, URGENCY_LABEL } from "./sheet.ts";
@@ -66,8 +67,8 @@ function drawLane(deal: DealView, start: string, on: string): string {
6667 const d = deal.deadlines[i]!;
6768 const u = urgencyOf(d, on);
6869 const tag = d.kind === "custom" ? d.label.split(" ")[0]! : KIND[d.kind].tag;
69 const flagged = deal.conflicts.some((c) => c.deadline_id === d.id);
70 return `<a class="marker" data-u="${u}"${flagged ? " data-conflict" : ""} ${opens(deal, d)} style="left:${at(x)};top:calc(${row} * 3rem)" aria-label="${escape(`${d.label}, ${spoken(d.due)} — ${URGENCY_LABEL[u]}${flagged ? " — falls on or after closing" : ""}`)}"><span class="dot"></span>${escape(tag)}</a>`;
70 const flagged = deal.conflicts.find((c) => c.deadline_id === d.id);
71 return `<a class="marker" data-u="${u}"${flagged !== undefined ? " data-conflict" : ""} ${opens(deal, d)} style="left:${at(x)};top:calc(${row} * 3rem)" aria-label="${escape(`${d.label}, ${spoken(d.due)} — ${URGENCY_LABEL[u]}${flagged ? ` — ${conflictShort(flagged)}` : ""}`)}"><span class="dot"></span>${escape(tag)}</a>`;
7172 })
7273 .join("");
7374 return `<li class="lane">
@@ -111,7 +112,7 @@ export function weekCard(deals: readonly DealView[], on: string, q = "", side: S
111112 (g) => `<h3 class="week-day">${escape(g.heading)}</h3>
112113 <ul class="week-list">${g.items
113114 .map(({ deal, deadline: d }) =>
114 weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}${closingNote(deal, d) === "" ? "" : ` · ${escape(closingNote(deal, d))}`}</b><small class="muted">${escape(deal.address)} · ${sideLabel(deal.side)} · ${owedBy(deal, d)}</small>${d.kind === "closing" ? clashLine(deal.closingConflicts, "small", false) : ""}${d.nonBusinessDay === null ? "" : `<small class="muted">Not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</small>`}${d.note === "" ? "" : `<small class="muted">${escape(d.note)}</small>`}</span>${badge(d, on)}</a></li>`),
115 weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}${whereNote(deal, d) === "" ? "" : ` · ${escape(whereNote(deal, d))}`}</b><small class="muted">${escape(deal.address)} · ${sideLabel(deal.side)} · ${owedBy(deal, d)}</small>${d.kind === "closing" ? clashLine(deal.closingConflicts, "small", false) : ""}${clashesLine(d.clashes, "small", false)}${d.nonBusinessDay === null ? "" : `<small class="muted">Not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</small>`}${d.note === "" ? "" : `<small class="muted">${escape(d.note)}</small>`}</span>${badge(d, on)}</a></li>`),
115116 )
116117 .join("")}</ul>`,
117118 )
src/pages/deal.ts +2 −2
@@ -11,7 +11,7 @@ import { agent as defaults, standard } from "../env.ts";
1111 import { CONTACT_ROLES, DEFAULT_LENGTHS, PARTY_LABEL, PARTY_ROLES, suggestedFor } from "../deadlines.ts";
1212 import { escape } from "../http.ts";
1313 import { coming, comingLine, type Coming } from "../coming.ts";
14 import { clashLine } from "../overlap.ts";
14 import { clashLine, clashesLine } from "../overlap.ts";
1515 import { closingLine } from "../closing.ts";
1616 import { commission, dollars, percent } from "../money.ts";
1717 import { anniversaryDrafts, checkinDrafts, drafts, pending, sentLabel, statusDrafts, type Agent } from "../reminders.ts";
@@ -206,7 +206,7 @@ export interface ClosingProblem {
206206
207207 /** The closing line, said in the one way: "Closing Nov 21 · 2:00 pm · Lakeside Title"; nothing for a time and place unset beyond the day the page already says. */
208208 function closingWhenLine(deal: DealView): string {
209 return (deal.closing_time === null && deal.closing_place === null ? "" : `<p class="summary" id="closing-when"><b>${escape(closingLine(deal))}</b></p>`) + clashLine(deal.closingConflicts);
209 return (deal.closing_time === null && deal.closing_place === null ? "" : `<p class="summary" id="closing-when"><b>${escape(closingLine(deal))}</b></p>`) + clashLine(deal.closingConflicts) + clashesLine(deal.deadlines.find((d) => d.kind === "closing")?.clashes ?? []);
210210 }
211211
212212 function closingForm(deal: DealView, path: string, problem: ClosingProblem | undefined): string {
src/pages/week.ts +4 −6
@@ -12,16 +12,14 @@ import { agent as defaults } from "../env.ts";
1212 import { asset, escape } from "../http.ts";
1313 import { STATUS } from "../timeline.ts";
1414 import type { Who } from "../who.ts";
15 import { appointmentNote, byDay, closingNote, owner, thisWeek } from "../week.ts";
16 import { clashLine } from "../overlap.ts";
15 import { byDay, owner, whereNote, thisWeek } from "../week.ts";
16 import { clashLine, clashesLine } from "../overlap.ts";
1717 import { layout } from "./layout.ts";
1818 import { sideLabel } from "./side.ts";
1919 import type { SideFilter } from "../side.ts";
2020
2121 const closingAt = (deal: DealView, d: DealView["deadlines"][number]): string => {
22 const where = closingNote(deal, d);
23 const appt = appointmentNote(d);
24 const text = where === "" ? appt : where;
22 const text = whereNote(deal, d);
2523 return text === "" ? "" : ` · ${escape(text)}`;
2624 };
2725
@@ -47,7 +45,7 @@ export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: re
4745 <p class="timeline-date">${escape(deal.address)} · ${sideLabel(deal.side)}</p>
4846 <p class="timeline-label"><b>${escape(d.label)}${closingAt(deal, d)}</b></p>
4947 <p class="timeline-owner">${escape(role)}${name === undefined ? "" : ` · ${escape(name)}`}</p>
50 ${d.kind === "closing" ? clashLine(deal.closingConflicts) : ""}
48 ${d.kind === "closing" ? clashLine(deal.closingConflicts) : ""}${clashesLine(d.clashes)}
5149 ${d.note === "" ? "" : `<p class="timeline-owner">${escape(d.note)}</p>`}
5250 <p class="timeline-status"><span aria-hidden="true">${s.mark}</span> ${s.word}</p>
5351 </li>`;
src/readme.test.ts added +22
@@ -0,0 +1,22 @@
1 import { expect, test } from "bun:test";
2 import { readFileSync } from "node:fs";
3
4 const readme = readFileSync(new URL("../README.md", import.meta.url), "utf8");
5
6 /** The anchor GitHub gives a heading: lower case, punctuation dropped, spaces to hyphens. */
7 const slug = (h: string) => h.toLowerCase().replace(/[^\w\s-]/g, "").trim().replace(/\s/g, "-");
8
9 test("every in-page link in the README lands on a heading in it", () => {
10 const anchors = new Set([...readme.matchAll(/^#{1,6}\s+(.+)$/gm)].map((m) => slug(m[1]!)));
11 const links = [...readme.replace(/\s+/g, " ").matchAll(/\]\(#([^)\s]*)\)/g)].map((m) => m[1]!);
12 expect(links.length).toBeGreaterThan(0);
13 for (const l of links) expect(anchors.has(l), `#${l}`).toBe(true);
14 });
15
16 test("the honest-limits section still says nothing is sent and links each feature", () => {
17 const section = readme.slice(readme.indexOf("## What is real"), readme.indexOf("## Signing in")).replace(/\s+/g, " ");
18 expect(section).toContain("no email or text message leaves the app");
19 for (const word of ["bring them back", "time and a place", "two hours apart", "anniversary", "Activity", "commission"]) {
20 expect(section).toContain(word);
21 }
22 });
src/routes.ts +9
@@ -345,6 +345,15 @@ export const DEAL: Schema = {
345345 description: "An open date due on a weekend or US federal holiday: next is the business day it rolls to. Null otherwise.",
346346 properties: { next: DATE },
347347 },
348 clashes: {
349 type: "array",
350 description: "Other timed open inspections, walkthroughs or closings of this agent the same day, less than two hours from this timed date. Empty when none.",
351 items: {
352 type: "object",
353 properties: { dealId: { type: "integer" }, address: { type: "string" }, label: { type: "string" }, time: CLOSING_TIME },
354 required: ["dealId", "address", "label", "time"],
355 },
356 },
348357 },
349358 },
350359 },
src/terminal.test.ts +23 −1
@@ -7,7 +7,7 @@ import { mkdtempSync } from "node:fs";
77 import { tmpdir } from "node:os";
88 import { join } from "node:path";
99 import { addDays, spoken, today, DEFAULT_ZONE } from "./dates.ts";
10 import { canChange, shown, addDeadline, addParty, createDeal, editParty, getDeal, listDeals, markDone, moveDeadline, sendReminder, updateDeal, type DealView } from "./deals.ts";
10 import { canChange, setAppointment, shown, addDeadline, addParty, createDeal, editParty, getDeal, listDeals, markDone, moveDeadline, sendReminder, updateDeal, type DealView } from "./deals.ts";
1111 import { openDb } from "./db.ts";
1212 import { terminal, type Terminal } from "./terminal.ts";
1313 import type { Who } from "./who.ts";
@@ -951,3 +951,25 @@ test("the deal view says which other closing the same day is less than two hours
951951 t.press("o");
952952 expect(lines(t).join("\n")).not.toContain("Also closing at");
953953 });
954
955 test("the deal view and the week say which other appointment the same day is less than two hours away", () => {
956 const make = (address: string, time: string) => {
957 const made = createDeal(db, alice, { openAnyway: true, address, buyer: "Bea Buyer", seller: "Sid Seller", contractDate: today(DEFAULT_ZONE), closingDate: addDays(today(DEFAULT_ZONE), 60) });
958 if (!made.ok) throw new Error(made.message);
959 const view = getDeal(db, alice, { id: made.value.id });
960 if (!view.ok) throw new Error(view.message);
961 const inspection = view.value.deadlines.find((d) => d.kind === "inspection")!;
962 db.query("UPDATE deadline SET due = ?1 WHERE id = ?2").run(addDays(today(DEFAULT_ZONE), 2), inspection.id);
963 const set = setAppointment(db, alice, { id: inspection.id, time, place: "" });
964 if (!set.ok) throw new Error(set.message);
965 };
966 make("7 Twin Ln", "10:00");
967 make("8 Twin Ln", "11:30");
968 const t = terminal(db, alice, context);
969 goTo(t, "Inspection period ends — 7 Twin Ln");
970 t.press("o");
971 expect(lines(t).join("\n")).toContain("Also at 11:30 am: Inspection, 8 Twin Ln");
972 t.press("o");
973 t.press("w");
974 expect(lines(t).join("\n")).toContain("Also at 10:00 am: Inspection, 7 Twin Ln");
975 });
src/terminal.ts +3 −2
@@ -87,7 +87,7 @@ import { people } from "./people.ts";
8787 import { reachedAt } from "./outbox.ts";
8888 import { addresses, refusal, when, wording } from "./activity.ts";
8989 import { listAudit } from "./actions.ts";
90 import { clashText } from "./overlap.ts";
90 import { clashText, clashesText } from "./overlap.ts";
9191 import { owner, thisWeek } from "./week.ts";
9292 import { SIDE_CHOICE, SIDE_LABEL, SIDE_REFUSAL, sideTyped } from "./side.ts";
9393
@@ -763,7 +763,8 @@ export function terminal(
763763 const lead = isOpen(date) ? dim(` reminds ${date.lead_days}d before`) : "";
764764 const note = date.note === "" ? "" : dim(` note: ${date.note}`);
765765 const where = appointmentLine(date) === "" ? "" : dim(` ${appointmentLine(date)}`);
766 return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${where}${flag}${lead}${moved}${note}`;
766 const clash = date.clashes.length === 0 ? "" : tint("overdue", ` ${clashesText(date.clashes)}`);
767 return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${where}${clash}${flag}${lead}${moved}${note}`;
767768 };
768769
769770 function screen(): string[] {
src/upgrade.test.ts +1
@@ -110,6 +110,7 @@ async function boots(list: string[], n: number, name: string) {
110110 }
111111 expect(shape(check), `schema at version ${n} differs from a fresh database`).toEqual(wanted);
112112 check.close();
113 expect((await get("/healthz")).status, `/healthz at version ${n}`).toBe(200);
113114 const pages = ["/", "/people"];
114115 if (hadDeal) pages.push("/deals/1", "/deals/1/timeline");
115116 for (const path of pages) {
src/week.ts +6
@@ -39,6 +39,12 @@ export function closingNote(deal: WeekDeal<unknown>, d: { kind?: string }): stri
3939 return d.kind === "closing" ? closingWhere({ closing_time: deal.closing_time ?? null, closing_place: deal.closing_place ?? null }) : "";
4040 }
4141
42 /** The time and place after a row's label: the closing's, or an inspection's or walkthrough's; "" when there is none. */
43 export function whereNote(deal: WeekDeal<unknown>, d: { kind: string; time?: string | null; place?: string | null }): string {
44 const where = closingNote(deal, d);
45 return where === "" ? appointmentNote(d) : where;
46 }
47
4248 export function thisWeek<D extends { due: string; done_at: string | null; waived_at: string | null }, Deal extends WeekDeal<D>>(
4349 deals: readonly Deal[],
4450 on: string,

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs