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
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/141-this-week-on-the-clock-and-the-printed-m → main 2 commits fork 1 thread · 1 unresolved
7 files
changed +70
−7
src/mcp.ts +2 −1
| @@ -104,7 +104,7 @@ export const tools: readonly Tool[] = [ | ||
| 104 | 104 | }, |
| 105 | 105 | { |
| 106 | 106 | 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.", | |
| 108 | 108 | inputSchema: { type: "object", properties: {} }, |
| 109 | 109 | run: (db, who) => { |
| 110 | 110 | const deals = listDeals(db, who); |
| @@ -116,6 +116,7 @@ export const tools: readonly Tool[] = [ | ||
| 116 | 116 | address: deal.address, |
| 117 | 117 | owner: owner(deal, deadline), |
| 118 | 118 | deadline, |
| 119 | ...(deadline.kind === "closing" ? { closing_time: deal.closing_time, closing_place: deal.closing_place } : {}), | |
| 119 | 120 | })), |
| 120 | 121 | } |
| 121 | 122 | : deals; |
src/pages/clock.ts +2 −2
| @@ -12,7 +12,7 @@ import { escape } from "../http.ts"; | ||
| 12 | 12 | import { agent as defaults } from "../env.ts"; |
| 13 | 13 | import { todaysDrafts, unsent, type Agent } from "../reminders.ts"; |
| 14 | 14 | import type { Who } from "../who.ts"; |
| 15 | import { byDay, thisWeek } from "../week.ts"; | |
| 15 | import { byDay, closingNote, thisWeek } from "../week.ts"; | |
| 16 | 16 | import { layout } from "./layout.ts"; |
| 17 | 17 | import { mayRestore } from "../actions.ts"; |
| 18 | 18 | 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 | ||
| 110 | 110 | (g) => `<h3 class="week-day">${escape(g.heading)}</h3> |
| 111 | 111 | <ul class="week-list">${g.items |
| 112 | 112 | .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>`), | |
| 114 | 114 | ) |
| 115 | 115 | .join("")}</ul>`, |
| 116 | 116 | ) |
src/pages/week.ts +7 −2
| @@ -12,11 +12,16 @@ import { agent as defaults } from "../env.ts"; | ||
| 12 | 12 | import { asset, escape } from "../http.ts"; |
| 13 | 13 | import { STATUS } from "../timeline.ts"; |
| 14 | 14 | import type { Who } from "../who.ts"; |
| 15 | import { byDay, owner, thisWeek } from "../week.ts"; | |
| 15 | import { byDay, closingNote, owner, thisWeek } from "../week.ts"; | |
| 16 | 16 | import { layout } from "./layout.ts"; |
| 17 | 17 | import { sideLabel } from "./side.ts"; |
| 18 | 18 | import type { SideFilter } from "../side.ts"; |
| 19 | 19 | |
| 20 | const closingAt = (deal: DealView, d: DealView["deadlines"][number]): string => { | |
| 21 | const where = closingNote(deal, d); | |
| 22 | return where === "" ? "" : ` · ${escape(where)}`; | |
| 23 | }; | |
| 24 | ||
| 20 | 25 | export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: readonly DealView[]; on: string; q?: string; side?: SideFilter }): string { |
| 21 | 26 | const { who, deals, on } = input; |
| 22 | 27 | const agent = input.agent ?? defaults; |
| @@ -37,7 +42,7 @@ export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: re | ||
| 37 | 42 | const s = STATUS[urgencyOf(d, on)]; |
| 38 | 43 | return `<li class="timeline-row" data-u="${urgencyOf(d, on)}"> |
| 39 | 44 | <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> | |
| 41 | 46 | <p class="timeline-owner">${escape(role)}${name === undefined ? "" : ` · ${escape(name)}`}</p> |
| 42 | 47 | ${d.note === "" ? "" : `<p class="timeline-owner">${escape(d.note)}</p>`} |
| 43 | 48 | <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 | ||
| 1072 | 1072 | const late = items.find((i: any) => i.address.startsWith("77 Harbor View") && i.deadline.label === "Inspection period ends"); |
| 1073 | 1073 | expect(late.owner.role).toBe("Buyer"); |
| 1074 | 1074 | 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); | |
| 1075 | 1080 | // What data-live refetches is this same section: once the date is done it is gone from it. |
| 1076 | 1081 | const card = async () => { |
| 1077 | 1082 | const page = await (await api("/", {}, week)).text(); |
src/week.page.test.ts +26 −1
| @@ -9,7 +9,8 @@ import { serve } from "./server.ts"; | ||
| 9 | 9 | import { sign } from "./who.ts"; |
| 10 | 10 | |
| 11 | 11 | 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 }); | |
| 13 | 14 | const base = `http://${server.hostname}:${server.port}`; |
| 14 | 15 | afterAll(() => server.stop(true)); |
| 15 | 16 | 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 () => { | ||
| 71 | 72 | const bad = await get(`/week?q=${"x".repeat(101)}`); |
| 72 | 73 | expect(bad.status).toBe(400); |
| 73 | 74 | }); |
| 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 <b>Title</b> & 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", () => { | ||
| 36 | 36 | const shut = { address: "C Street", closed: true, deadlines: [d("2026-11-03")] }; |
| 37 | 37 | expect(thisWeek([...deals, shut], on).some((i) => i.deal.address === "C Street")).toBe(false); |
| 38 | 38 | }); |
| 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 @@ | ||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | import { addDays, spoken } from "./dates.ts"; |
| 7 | import { closingWhere } from "./closing.ts"; | |
| 7 | 8 | import { isOpen, PARTY_LABEL, type PartyRole } from "./deadlines.ts"; |
| 8 | 9 | |
| 9 | 10 | /** How many days past today still count as this week. */ |
| @@ -15,6 +16,9 @@ export interface WeekDeal<D> { | ||
| 15 | 16 | readonly closed?: boolean; |
| 16 | 17 | /** A deal that fell through is off the clock too. */ |
| 17 | 18 | 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; | |
| 18 | 22 | readonly deadlines: readonly D[]; |
| 19 | 23 | } |
| 20 | 24 | |
| @@ -23,6 +27,15 @@ export interface WeekItem<Deal, D> { | ||
| 23 | 27 | readonly deadline: D; |
| 24 | 28 | } |
| 25 | 29 | |
| 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 | ||
| 26 | 39 | export function thisWeek<D extends { due: string; done_at: string | null; waived_at: string | null }, Deal extends WeekDeal<D>>( |
| 27 | 40 | deals: readonly Deal[], |
| 28 | 41 | on: string, |
| @@ -35,7 +48,10 @@ export function thisWeek<D extends { due: string; done_at: string | null; waived | ||
| 35 | 48 | ) |
| 36 | 49 | .sort( |
| 37 | 50 | (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), | |
| 39 | 55 | ); |
| 40 | 56 | } |
| 41 | 57 |
new above
offline
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.