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

This week, on the clock and the printed Monday sheet, shows each closing's time and place, like "Closing · 2:00 pm at Lakeside Title", so the week's closings are planned from one page #144

Merged opened this

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

Merged

mason/deal-clock:mason/141-this-week-on-the-clock-and-the-printed-m → main 2 commits fork 1 thread · 1 unresolved

  • Merged. mason/141-this-week-on-the-clock-and-the-printed-m was merged into main as 706c5ac.

Review

Sign in to review this change.
7 files changed +70 −7
src/mcp.ts +2 −1
@@ -104,7 +104,7 @@ export const tools: readonly Tool[] = [
104104 },
105105 {
106106 name: "this_week",
107 description: "Every open date that is overdue or due in the next seven days, oldest first, then by address, with the deal's address and who owes it.",
107 description: "Every open date that is overdue or due in the next seven days, oldest first, then by address, with the deal's address and who owes it; a closing row also carries closing_time and closing_place.",
108108 inputSchema: { type: "object", properties: {} },
109109 run: (db, who) => {
110110 const deals = listDeals(db, who);
@@ -116,6 +116,7 @@ export const tools: readonly Tool[] = [
116116 address: deal.address,
117117 owner: owner(deal, deadline),
118118 deadline,
119 ...(deadline.kind === "closing" ? { closing_time: deal.closing_time, closing_place: deal.closing_place } : {}),

Behaviour added without a test that fails without it. Cover closing_time/closing_place on closing rows (and their absence on other rows) in the this_week MCP test.

119120 })),
120121 }
121122 : deals;
src/pages/clock.ts +2 −2
@@ -12,7 +12,7 @@ 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 { byDay, thisWeek } from "../week.ts";
15 import { byDay, closingNote, thisWeek } from "../week.ts";
1616 import { layout } from "./layout.ts";
1717 import { mayRestore } from "../actions.ts";
1818 import { badge, draftLink, opens, owedBy, URGENCY_LABEL } from "./sheet.ts";
@@ -110,7 +110,7 @@ export function weekCard(deals: readonly DealView[], on: string, q = "", side: S
110110 (g) => `<h3 class="week-day">${escape(g.heading)}</h3>
111111 <ul class="week-list">${g.items
112112 .map(({ deal, deadline: d }) =>
113 weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}</b><small class="muted">${escape(deal.address)} · ${sideLabel(deal.side)} · ${owedBy(deal, d)}</small>${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>`),
113 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.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>`),
114114 )
115115 .join("")}</ul>`,
116116 )
src/pages/week.ts +7 −2
@@ -12,11 +12,16 @@ 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 { byDay, owner, thisWeek } from "../week.ts";
15 import { byDay, closingNote, owner, thisWeek } from "../week.ts";
1616 import { layout } from "./layout.ts";
1717 import { sideLabel } from "./side.ts";
1818 import type { SideFilter } from "../side.ts";
1919
20 const closingAt = (deal: DealView, d: DealView["deadlines"][number]): string => {
21 const where = closingNote(deal, d);
22 return where === "" ? "" : ` · ${escape(where)}`;
23 };
24
2025 export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: readonly DealView[]; on: string; q?: string; side?: SideFilter }): string {
2126 const { who, deals, on } = input;
2227 const agent = input.agent ?? defaults;
@@ -37,7 +42,7 @@ export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: re
3742 const s = STATUS[urgencyOf(d, on)];
3843 return `<li class="timeline-row" data-u="${urgencyOf(d, on)}">
3944 <p class="timeline-date">${escape(deal.address)} · ${sideLabel(deal.side)}</p>
40 <p class="timeline-label"><b>${escape(d.label)}</b></p>
45 <p class="timeline-label"><b>${escape(d.label)}${closingAt(deal, d)}</b></p>
4146 <p class="timeline-owner">${escape(role)}${name === undefined ? "" : ` · ${escape(name)}`}</p>
4247 ${d.note === "" ? "" : `<p class="timeline-owner">${escape(d.note)}</p>`}
4348 <p class="timeline-status"><span aria-hidden="true">${s.mark}</span> ${s.word}</p>
src/server.test.ts +5
@@ -1072,6 +1072,11 @@ test("This week over MCP lists the same dates, for a signed-in account only; a d
10721072 const late = items.find((i: any) => i.address.startsWith("77 Harbor View") && i.deadline.label === "Inspection period ends");
10731073 expect(late.owner.role).toBe("Buyer");
10741074 expect(items.every((i: any) => i.deadline.done_at === null)).toBe(true);
1075 // Only a closing row carries where and when it happens (null when the agent has not said).
1076 const closings = items.filter((i: any) => i.deadline.kind === "closing");
1077 expect(closings.length).toBeGreaterThan(0);
1078 expect(closings.every((i: any) => "closing_time" in i && "closing_place" in i)).toBe(true);
1079 expect(items.filter((i: any) => i.deadline.kind !== "closing").some((i: any) => "closing_time" in i || "closing_place" in i)).toBe(false);
10751080 // What data-live refetches is this same section: once the date is done it is gone from it.
10761081 const card = async () => {
10771082 const page = await (await api("/", {}, week)).text();
src/week.page.test.ts +26 −1
@@ -9,7 +9,8 @@ import { serve } from "./server.ts";
99 import { sign } from "./who.ts";
1010
1111 const KEY = "a-key-only-the-forge-holds";
12 const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-weekpage-")), identityKey: KEY });
12 const dir = mkdtempSync(join(tmpdir(), "app-weekpage-"));
13 const server = serve({ port: 0, dataDir: dir, identityKey: KEY });
1314 const base = `http://${server.hostname}:${server.port}`;
1415 afterAll(() => server.stop(true));
1516 const identity = `u1|alice|user|${Date.now() + 600_000}`;
@@ -71,3 +72,27 @@ test("Find narrows the sheet and a bad q is refused", async () => {
7172 const bad = await get(`/week?q=${"x".repeat(101)}`);
7273 expect(bad.status).toBe(400);
7374 });
75
76 test("a closing row says its time and place, and the place is escaped", async () => {
77 forgetRationing();
78 const html = await (await get("/week")).text();
79 expect(html).toContain("Closing · 2:00 pm at Bayside Title, 400 Main St");
80 const clock = await (await get("/")).text();
81 expect(clock.slice(clock.indexOf('id="week"'))).toContain("Closing · 2:00 pm at Bayside Title, 400 Main St");
82 });
83
84 test("a place with markup in it is escaped on the sheet", async () => {
85 const { openDb } = await import("./db.ts");
86 const { createDeal, updateDeal } = await import("./deals.ts");
87 const { today } = await import("./dates.ts");
88 const db = openDb(dir);
89 const me = { role: "user" as const, id: "u1", name: "alice" };
90 const made = createDeal(db, me, { address: "9 Escape Way", buyer: "A B", seller: "C D", contractDate: addDays(today(), -20), closingDate: addDays(today(), 1), openAnyway: true });
91 if (!made.ok) throw new Error(made.message);
92 const set = updateDeal(db, me, { id: made.value.id, closingTime: "08:00", closingPlace: "<b>Title</b> & Co" });
93 if (!set.ok) throw new Error(set.message);
94 forgetRationing();
95 const html = await (await get("/week")).text();
96 expect(html).toContain("8:00 am at &lt;b&gt;Title&lt;/b&gt; &amp; Co");
97 expect(html).not.toContain("<b>Title</b>");
98 });
src/week.test.ts +11
@@ -36,3 +36,14 @@ test("a closed deal's dates are left out", () => {
3636 const shut = { address: "C Street", closed: true, deadlines: [d("2026-11-03")] };
3737 expect(thisWeek([...deals, shut], on).some((i) => i.deal.address === "C Street")).toBe(false);
3838 });
39
40 test("on one day timed closings come first by time, then the other rows as before", () => {
41 const c = (address: string, time: string | null) => ({
42 address,
43 closing_time: time,
44 deadlines: [{ ...d("2026-11-04"), kind: "closing" }],
45 });
46 const other = { address: "A Street", deadlines: [{ ...d("2026-11-04"), kind: "inspection" }] };
47 const rows = thisWeek([other, c("Z Street", "15:00"), c("Y Street", null), c("X Street", "09:30")], on);
48 expect(rows.map((i) => i.deal.address)).toEqual(["X Street", "Z Street", "A Street", "Y Street"]);
49 });
src/week.ts +17 −1
@@ -4,6 +4,7 @@
44 */
55
66 import { addDays, spoken } from "./dates.ts";
7 import { closingWhere } from "./closing.ts";
78 import { isOpen, PARTY_LABEL, type PartyRole } from "./deadlines.ts";
89
910 /** How many days past today still count as this week. */
@@ -15,6 +16,9 @@ export interface WeekDeal<D> {
1516 readonly closed?: boolean;
1617 /** A deal that fell through is off the clock too. */
1718 readonly fell_through?: boolean;
19 /** When the closing is, HH:MM, if the agent said. */
20 readonly closing_time?: string | null;
21 readonly closing_place?: string | null;
1822 readonly deadlines: readonly D[];
1923 }
2024
@@ -23,6 +27,15 @@ export interface WeekItem<Deal, D> {
2327 readonly deadline: D;
2428 }
2529
30 /** Within a day, timed closings come first by time; everything else keeps its place after them. */
31 const closingTime = (item: { deal: WeekDeal<unknown>; deadline: unknown }): string | undefined =>
32 (item.deadline as { kind?: string }).kind === "closing" ? (item.deal.closing_time ?? undefined) : undefined;
33
34 /** "2:00 pm at Lakeside Title" for a closing row that has a time or place; "" for any other row. */
35 export function closingNote(deal: WeekDeal<unknown>, d: { kind?: string }): string {
36 return d.kind === "closing" ? closingWhere({ closing_time: deal.closing_time ?? null, closing_place: deal.closing_place ?? null }) : "";
37 }
38
2639 export function thisWeek<D extends { due: string; done_at: string | null; waived_at: string | null }, Deal extends WeekDeal<D>>(
2740 deals: readonly Deal[],
2841 on: string,
@@ -35,7 +48,10 @@ export function thisWeek<D extends { due: string; done_at: string | null; waived
3548 )
3649 .sort(
3750 (a, b) =>
38 a.deadline.due.localeCompare(b.deadline.due) || a.deal.address.localeCompare(b.deal.address),
51 a.deadline.due.localeCompare(b.deadline.due) ||
52 (closingTime(a) === undefined ? 1 : 0) - (closingTime(b) === undefined ? 1 : 0) ||
53 (closingTime(a) ?? "").localeCompare(closingTime(b) ?? "") ||
54 a.deal.address.localeCompare(b.deal.address),
3955 );
4056 }
4157

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs