Public: anyone can read this; the crew can change it.
A date that falls on or after closing is flagged on the clock, its sheet, the deal page, the API and MCP, so a slipped contingency is seen before the closing table #61
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/58-a-date-that-falls-on-or-after-closing-is → main 6 commits fork 1 thread · 1 unresolved
16 files
changed +325
−15
README.md +4 −1
| @@ -77,7 +77,10 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture | ||
| 77 | 77 | made it. No other date moves. A *Date changed* notice is drafted for each |
| 78 | 78 | party the date reminds, naming the old and the new date (not the reason); |
| 79 | 79 | it waits under Reminders for today like any other, and you send, edit or |
| 80 | decline it. Move the date again and an unsent notice is replaced. | |
| 80 | decline it. Move the date again and an unsent notice is replaced. If you move a date to or past the closing date, the move | |
| 81 | still happens, but the notice says so, the date's marker on the clock | |
| 82 | carries a ! and the sheet and the deal page say which dates now fall | |
| 83 | after closing. | |
| 81 | 84 | 6. **See a date that was moved.** On 9 Orchard Row, open the appraisal |
| 82 | 85 | marker. The sheet shows where it moved from and to, with the reason |
| 83 | 86 | the appraiser gave. |
contract/openapi.json +29
| @@ -1146,6 +1146,35 @@ | ||
| 1146 | 1146 | } |
| 1147 | 1147 | } |
| 1148 | 1148 | }, |
| 1149 | "conflicts": { | |
| 1150 | "type": "array", | |
| 1151 | "description": "Open dates (not Closing) due on or after the open Closing date: a slipped contingency. Empty when the deal is in order or closed.", | |
| 1152 | "items": { | |
| 1153 | "type": "object", | |
| 1154 | "properties": { | |
| 1155 | "deadline_id": { | |
| 1156 | "type": "integer" | |
| 1157 | }, | |
| 1158 | "label": { | |
| 1159 | "type": "string" | |
| 1160 | }, | |
| 1161 | "due": { | |
| 1162 | "type": "string", | |
| 1163 | "format": "date" | |
| 1164 | }, | |
| 1165 | "closing": { | |
| 1166 | "type": "string", | |
| 1167 | "format": "date" | |
| 1168 | } | |
| 1169 | }, | |
| 1170 | "required": [ | |
| 1171 | "deadline_id", | |
| 1172 | "label", | |
| 1173 | "due", | |
| 1174 | "closing" | |
| 1175 | ] | |
| 1176 | } | |
| 1177 | }, | |
| 1149 | 1178 | "declined": { |
| 1150 | 1179 | "type": "array", |
| 1151 | 1180 | "items": { |
docs/TECHNICAL.md +2
| @@ -225,3 +225,5 @@ it does is `src/terminal.ts`, which `src/terminal.test.ts` drives key by key. | ||
| 225 | 225 | The forge sets `PORT`, `FORGE_APP_DATA`, `FORGE_APP_ENV` (`production` or |
| 226 | 226 | `preview`), `FORGE_APP_URL`, `FORGE_APP_COMMIT`, `FORGE_APP_SSH` and |
| 227 | 227 | `FORGE_APP_IDENTITY_KEY` when it starts the app. `forge.json` says how. |
| 228 | ||
| 229 | `conflicts` on a deal (`GET /api/deals/:id`, the list, MCP `get_deal`, the terminal deal view) lists each open, non-Closing date due on or after the open Closing date: `{deadline_id, label, due, closing}`. It is computed once per assembled deal by `src/order.ts` and is empty for a closed deal and for done dates. A move still succeeds; the form notice names the conflict. |
src/deals.ts +16
| @@ -21,6 +21,7 @@ import { | ||
| 21 | 21 | } from "./deadlines.ts"; |
| 22 | 22 | import { agent as defaultAgent, LENGTH_MAX, standard } from "./env.ts"; |
| 23 | 23 | import { emit } from "./live.ts"; |
| 24 | import { conflictLine, conflicts, type Conflict } from "./order.ts"; | |
| 24 | 25 | import { draftsFor, moveKey, type Agent, type Draft } from "./reminders.ts"; |
| 25 | 26 | import { audited, fail, ok, refuse, type Result } from "./result.ts"; |
| 26 | 27 | import type { Who } from "./who.ts"; |
| @@ -117,6 +118,8 @@ export interface DealView extends Deal { | ||
| 117 | 118 | readonly deadlines: readonly DeadlineView[]; |
| 118 | 119 | readonly sent: readonly Sent[]; |
| 119 | 120 | readonly declined: readonly Declined[]; |
| 121 | /** Open dates due on or after the open closing date (`order.ts`). */ | |
| 122 | readonly conflicts: readonly Conflict[]; | |
| 120 | 123 | } |
| 121 | 124 | |
| 122 | 125 | export type Moment = "before" | "day_of" | "late" | "moved"; |
| @@ -190,6 +193,7 @@ function assemble(deal: Deal, rows: Children): DealView { | ||
| 190 | 193 | })), |
| 191 | 194 | sent: rows.sent, |
| 192 | 195 | declined: rows.declined, |
| 196 | conflicts: conflicts(rows.deadlines), | |
| 193 | 197 | }; |
| 194 | 198 | } |
| 195 | 199 | |
| @@ -285,6 +289,18 @@ function viewMany(db: Database, where: string, params: string[]): DealView[] { | ||
| 285 | 289 | ); |
| 286 | 290 | } |
| 287 | 291 | |
| 292 | /** The dates now out of order on a deal after a change to it: what a door says beside "moved" or "added". */ | |
| 293 | export function conflictsOf(db: Database, who: Who, dealId: number): readonly Conflict[] { | |
| 294 | const found = getDeal(db, who, { id: dealId }); | |
| 295 | return found.ok ? found.value.conflicts : []; | |
| 296 | } | |
| 297 | ||
| 298 | /** A change's notice with the dates it left out of order, in words. */ | |
| 299 | export function withConflicts(db: Database, who: Who, dealId: number, said: string): string { | |
| 300 | const out = conflictsOf(db, who, dealId); | |
| 301 | return out.length === 0 ? said : `${said} ${out.map(conflictLine).join(" ")}`; | |
| 302 | } | |
| 303 | ||
| 288 | 304 | export function listDeals(db: Database, who: Who): Result<DealView[]> { |
| 289 | 305 | const may = permit(who, "deal", "list"); |
| 290 | 306 | if (may === "no") |
src/mcp.ts +12 −5
| @@ -9,9 +9,11 @@ | ||
| 9 | 9 | import type { Database } from "bun:sqlite"; |
| 10 | 10 | import { restoreSamples, type Result } from "./actions.ts"; |
| 11 | 11 | import { today } from "./dates.ts"; |
| 12 | import { ok } from "./result.ts"; | |
| 12 | 13 | import { DEFAULT_LENGTHS, PARTY_ROLES } from "./deadlines.ts"; |
| 13 | 14 | import { |
| 14 | 15 | addDeadline, |
| 16 | conflictsOf, | |
| 15 | 17 | addParty, |
| 16 | 18 | createDeal, |
| 17 | 19 | deleteDeal, |
| @@ -61,7 +63,7 @@ export const tools: readonly Tool[] = [ | ||
| 61 | 63 | }, |
| 62 | 64 | { |
| 63 | 65 | name: "get_deal", |
| 64 | description: "One deal by id.", | |
| 66 | description: "One deal by id. conflicts lists the open dates due on or after closing (a slipped contingency); empty when in order.", | |
| 65 | 67 | inputSchema: { type: "object", properties: { id: { type: "integer" } }, required: ["id"] }, |
| 66 | 68 | run: (db, who, args) => getDeal(db, who, { id: Number(args.id) }), |
| 67 | 69 | }, |
| @@ -125,7 +127,7 @@ export const tools: readonly Tool[] = [ | ||
| 125 | 127 | }, |
| 126 | 128 | { |
| 127 | 129 | name: "move_date", |
| 128 | description: "Move one date, and only that one, giving the reason.", | |
| 130 | description: "Move one date, and only that one, giving the reason. The answer lists conflicts: open dates now due on or after closing.", | |
| 129 | 131 | inputSchema: { |
| 130 | 132 | type: "object", |
| 131 | 133 | properties: { |
| @@ -135,7 +137,10 @@ export const tools: readonly Tool[] = [ | ||
| 135 | 137 | }, |
| 136 | 138 | required: ["id", "due", "reason"], |
| 137 | 139 | }, |
| 138 | run: (db, who, args) => moveDeadline(db, who, { id: Number(args.id), due: args.due, reason: args.reason }), | |
| 140 | run: (db, who, args) => { | |
| 141 | const moved = moveDeadline(db, who, { id: Number(args.id), due: args.due, reason: args.reason }); | |
| 142 | return moved.ok ? ok({ ...moved.value, conflicts: conflictsOf(db, who, moved.value.deal_id) }) : moved; | |
| 143 | }, | |
| 139 | 144 | }, |
| 140 | 145 | { |
| 141 | 146 | name: "send_reminder", |
| @@ -234,8 +239,10 @@ export const tools: readonly Tool[] = [ | ||
| 234 | 239 | }, |
| 235 | 240 | required: ["deal_id", "label", "due", "owes"], |
| 236 | 241 | }, |
| 237 | run: (db, who, a) => | |
| 238 | addDeadline(db, who, { dealId: Number(a.deal_id), label: a.label, due: a.due, owes: a.owes, what: a.details }), | |
| 242 | run: (db, who, a) => { | |
| 243 | const added = addDeadline(db, who, { dealId: Number(a.deal_id), label: a.label, due: a.due, owes: a.owes, what: a.details }); | |
| 244 | return added.ok ? ok({ ...added.value, conflicts: conflictsOf(db, who, added.value.deal_id) }) : added; | |
| 245 | }, | |
| 239 | 246 | }, |
| 240 | 247 | { |
| 241 | 248 | name: "update_address", |
src/order.page.test.ts added +94
| @@ -0,0 +1,94 @@ | ||
| 1 | /** A date moved past closing is flagged on the clock, the sheet, the deal page, the API and the terminal; a fresh boot is clean. */ | |
| 2 | import { afterAll, 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 { forgetRationing } from "./security.ts"; | |
| 7 | import { serve } from "./server.ts"; | |
| 8 | import { sign } from "./who.ts"; | |
| 9 | ||
| 10 | const KEY = "a-key-only-the-forge-holds"; | |
| 11 | const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-order-")), identityKey: KEY }); | |
| 12 | const base = `http://${server.hostname}:${server.port}`; | |
| 13 | afterAll(() => server.stop(true)); | |
| 14 | ||
| 15 | const identity = `u1|alice|user|${Date.now() + 600_000}`; | |
| 16 | const alice = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) }; | |
| 17 | type Deal = { | |
| 18 | id: number; | |
| 19 | address: string; | |
| 20 | conflicts: { deadline_id: number; label: string; due: string; closing: string }[]; | |
| 21 | deadlines: { id: number; kind: string; label: string; due: string }[]; | |
| 22 | }; | |
| 23 | const deals = async (): Promise<Deal[]> => (await fetch(`${base}/api/deals`, { headers: alice })).json() as Promise<Deal[]>; | |
| 24 | ||
| 25 | test("no sample deal is flagged on a fresh boot", async () => { | |
| 26 | const all = await deals(); | |
| 27 | expect(all.length).toBeGreaterThan(0); | |
| 28 | for (const deal of all) expect(deal.conflicts).toEqual([]); | |
| 29 | const page = await (await fetch(`${base}/`, { headers: alice })).text(); | |
| 30 | expect(page).not.toContain("data-conflict"); | |
| 31 | expect(page).not.toContain("out of order"); | |
| 32 | }); | |
| 33 | ||
| 34 | test("moving Alder Lane's financing past closing succeeds and shows the flag everywhere", async () => { | |
| 35 | forgetRationing(); | |
| 36 | const alder = (await deals()).find((d) => d.address === "1418 Alder Lane")!; | |
| 37 | const financing = alder.deadlines.find((d) => d.kind === "financing")!; | |
| 38 | const closing = alder.deadlines.find((d) => d.kind === "closing")!; | |
| 39 | const past = new Date(Date.parse(`${closing.due}T00:00:00Z`) + 4 * 86_400_000).toISOString().slice(0, 10); | |
| 40 | const body = new FormData(); | |
| 41 | body.set("due", past); | |
| 42 | body.set("reason", "Lender needs more time"); | |
| 43 | body.set("to", `/deals/${alder.id}`); | |
| 44 | const moved = await fetch(`${base}/deadlines/${financing.id}/move`, { method: "POST", body, headers: alice, redirect: "manual" }); | |
| 45 | expect(moved.status).toBe(303); | |
| 46 | expect(decodeURIComponent(moved.headers.get("set-cookie") ?? "")).toContain("now falls after closing"); | |
| 47 | ||
| 48 | const api = (await (await fetch(`${base}/api/deals/${alder.id}`, { headers: alice })).json()) as Deal; | |
| 49 | expect(api.conflicts).toEqual([{ deadline_id: financing.id, label: financing.label, due: past, closing: closing.due }]); | |
| 50 | ||
| 51 | const sheets = await (await fetch(`${base}/deals/${alder.id}/sheets`, { headers: alice })).text(); | |
| 52 | expect(sheets).toContain("now falls after closing"); | |
| 53 | const deal = await (await fetch(`${base}/deals/${alder.id}`, { headers: alice })).text(); | |
| 54 | expect(deal).toContain('class="conflict"'); | |
| 55 | const clock = await (await fetch(`${base}/`, { headers: alice })).text(); | |
| 56 | expect(clock).toContain("data-conflict"); | |
| 57 | expect(clock).toContain("falls on or after closing"); | |
| 58 | expect(clock).toContain("1 out of order"); | |
| 59 | }); | |
| 60 | ||
| 61 | test("adding a date on closing day succeeds and the notice says so", async () => { | |
| 62 | forgetRationing(); | |
| 63 | const alder = (await deals()).find((d) => d.address === "1418 Alder Lane")!; | |
| 64 | const closing = alder.deadlines.find((d) => d.kind === "closing")!; | |
| 65 | const body = new FormData(); | |
| 66 | body.set("label", "Rate lock"); | |
| 67 | body.set("due", closing.due); | |
| 68 | body.set("owes", "buyer"); | |
| 69 | const added = await fetch(`${base}/deals/${alder.id}/deadlines`, { method: "POST", body, headers: alice, redirect: "manual" }); | |
| 70 | expect(added.status).toBe(303); | |
| 71 | const notice = decodeURIComponent(added.headers.get("set-cookie") ?? ""); | |
| 72 | expect(notice).toContain("Date added."); | |
| 73 | expect(notice).toContain("Rate lock"); | |
| 74 | expect(notice).toContain("now falls on closing"); | |
| 75 | const sheets = await (await fetch(`${base}/deals/${alder.id}/sheets`, { headers: alice })).text(); | |
| 76 | expect(sheets).toContain("now falls on closing"); | |
| 77 | }); | |
| 78 | ||
| 79 | test("MCP move_date and add_date answer with the conflicts", async () => { | |
| 80 | forgetRationing(); | |
| 81 | const alder = (await deals()).find((d) => d.address === "1418 Alder Lane")!; | |
| 82 | const closing = alder.deadlines.find((d) => d.kind === "closing")!; | |
| 83 | const call = async (name: string, args: Record<string, unknown>) => { | |
| 84 | const res = await fetch(`${base}/mcp`, { | |
| 85 | method: "POST", | |
| 86 | headers: { ...alice, "content-type": "application/json" }, | |
| 87 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } }), | |
| 88 | }); | |
| 89 | const out = (await res.json()) as { result: { content: { text: string }[] } }; | |
| 90 | return JSON.parse(out.result.content[0]!.text) as { conflicts: { label: string }[] }; | |
| 91 | }; | |
| 92 | const added = await call("add_date", { deal_id: alder.id, label: "Late survey", due: closing.due, owes: "buyer" }); | |
| 93 | expect(added.conflicts.map((c) => c.label)).toContain("Late survey"); | |
| 94 | }); |
src/order.test.ts added +34
| @@ -0,0 +1,34 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { conflictLine, conflicts } from "./order.ts"; | |
| 3 | ||
| 4 | const d = (id: number, kind: string, due: string, done_at: string | null = null) => ({ | |
| 5 | id, | |
| 6 | kind, | |
| 7 | label: kind === "financing" ? "Financing" : kind === "closing" ? "Closing" : kind, | |
| 8 | due, | |
| 9 | done_at, | |
| 10 | }); | |
| 11 | ||
| 12 | test("an open date before closing is in order; on and after closing are flagged", () => { | |
| 13 | const closing = d(9, "closing", "2026-11-20"); | |
| 14 | expect(conflicts([d(1, "financing", "2026-11-19"), closing])).toEqual([]); | |
| 15 | expect(conflicts([d(1, "financing", "2026-11-20"), closing])).toEqual([ | |
| 16 | { deadline_id: 1, label: "Financing", due: "2026-11-20", closing: "2026-11-20" }, | |
| 17 | ]); | |
| 18 | expect(conflicts([closing, d(1, "financing", "2026-11-24")])).toEqual([ | |
| 19 | { deadline_id: 1, label: "Financing", due: "2026-11-24", closing: "2026-11-20" }, | |
| 20 | ]); | |
| 21 | }); | |
| 22 | ||
| 23 | test("a done date is never flagged, nor is any date of a closed deal", () => { | |
| 24 | const closing = d(9, "closing", "2026-11-20"); | |
| 25 | expect(conflicts([d(1, "financing", "2026-11-24", "2026-11-01T00:00:00Z"), closing])).toEqual([]); | |
| 26 | expect(conflicts([d(1, "financing", "2026-11-24"), d(9, "closing", "2026-11-20", "2026-11-20T00:00:00Z")])).toEqual([]); | |
| 27 | expect(conflicts([d(1, "financing", "2026-11-24")])).toEqual([]); | |
| 28 | }); | |
| 29 | ||
| 30 | test("the line says it in words", () => { | |
| 31 | const c = { deadline_id: 1, label: "Financing", due: "2026-11-24", closing: "2026-11-20" }; | |
| 32 | expect(conflictLine(c)).toBe("Financing (Nov 24) now falls after closing (Nov 20): move one or the other."); | |
| 33 | expect(conflictLine({ ...c, due: "2026-11-20" })).toContain("now falls on closing"); | |
| 34 | }); |
src/order.ts added +36
| @@ -0,0 +1,36 @@ | ||
| 1 | /** | |
| 2 | * Dates out of order within one deal: an open date due on or after the open | |
| 3 | * closing date. Pure, on plain data, one pass over the dates; `deals.ts` | |
| 4 | * computes it once when a deal is assembled and every door shows that. | |
| 5 | */ | |
| 6 | ||
| 7 | import { short } from "./dates.ts"; | |
| 8 | ||
| 9 | /** An open, non-closing date that falls on or after the closing date. */ | |
| 10 | export interface Conflict { | |
| 11 | readonly deadline_id: number; | |
| 12 | readonly label: string; | |
| 13 | readonly due: string; | |
| 14 | readonly closing: string; | |
| 15 | } | |
| 16 | ||
| 17 | interface Dated { | |
| 18 | readonly id: number; | |
| 19 | readonly kind: string; | |
| 20 | readonly label: string; | |
| 21 | readonly due: string; | |
| 22 | readonly done_at: string | null; | |
| 23 | } | |
| 24 | ||
| 25 | /** Each open date due on or after the closing date; none once the closing date is done (the deal is closed) or when there is none. */ | |
| 26 | export function conflicts(deadlines: readonly Dated[]): Conflict[] { | |
| 27 | const closing = deadlines.find((d) => d.kind === "closing"); | |
| 28 | if (closing === undefined || closing.done_at !== null) return []; | |
| 29 | return deadlines | |
| 30 | .filter((d) => d.kind !== "closing" && d.done_at === null && d.due >= closing.due) | |
| 31 | .map((d) => ({ deadline_id: d.id, label: d.label, due: d.due, closing: closing.due })); | |
| 32 | } | |
| 33 | ||
| 34 | /** "Financing (Nov 24) now falls after closing (Nov 20): move one or the other." */ | |
| 35 | export const conflictLine = (c: Conflict): string => | |
| 36 | `${c.label} (${short(c.due)}) now falls ${c.due === c.closing ? "on" : "after"} closing (${short(c.closing)}): move one or the other.`; |
src/pages/clock.ts +3 −2
| @@ -60,11 +60,12 @@ function drawLane(deal: DealView, start: string, on: string): string { | ||
| 60 | 60 | const d = deal.deadlines[i]!; |
| 61 | 61 | const u = urgency(d.due, on, d.done_at !== null); |
| 62 | 62 | const tag = d.kind === "custom" ? d.label.split(" ")[0]! : KIND[d.kind].tag; |
| 63 | return `<a class="marker" data-u="${u}" ${opens(deal, d)} style="left:${at(x)};top:calc(${row} * 3rem)" aria-label="${escape(`${d.label}, ${spoken(d.due)} — ${URGENCY_LABEL[u]}`)}"><span class="dot"></span>${escape(tag)}</a>`; | |
| 63 | const flagged = deal.conflicts.some((c) => c.deadline_id === d.id); | |
| 64 | 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>`; | |
| 64 | 65 | }) |
| 65 | 66 | .join(""); |
| 66 | 67 | return `<li class="lane"> |
| 67 | <div class="lane-head"><a href="/deals/${deal.id}">${escape(deal.address)}</a> <small class="muted">closes ${escape(spoken(deal.closing))} · ${escape(relative(deal.closing, on))}</small></div> | |
| 68 | <div class="lane-head"><a href="/deals/${deal.id}">${escape(deal.address)}</a> <small class="muted">${deal.conflicts.length === 0 ? "" : `<b class="u-overdue">${deal.conflicts.length} out of order</b> · `}closes ${escape(spoken(deal.closing))} · ${escape(relative(deal.closing, on))}</small></div> | |
| 68 | 69 | <div class="track" style="height:calc(${height} * 3rem)">${markers}</div> |
| 69 | 70 | </li>`; |
| 70 | 71 | } |
src/pages/deal.ts +2 −1
| @@ -12,7 +12,7 @@ import { escape } from "../http.ts"; | ||
| 12 | 12 | import { MOMENT_LABEL } from "../reminders.ts"; |
| 13 | 13 | import type { Who } from "../who.ts"; |
| 14 | 14 | import { layout } from "./layout.ts"; |
| 15 | import { badge, dueLine, owedBy, sheet, sheetId } from "./sheet.ts"; | |
| 15 | import { badge, conflictLines, dueLine, owedBy, sheet, sheetId } from "./sheet.ts"; | |
| 16 | 16 | |
| 17 | 17 | const roleOptions = (selected?: string): string => |
| 18 | 18 | PARTY_ROLES.map( |
| @@ -128,6 +128,7 @@ export function dealPage(input: { | ||
| 128 | 128 | <div id="deal" data-live="deal.changed"> |
| 129 | 129 | <section class="card"> |
| 130 | 130 | <h2>Dates</h2> |
| 131 | ${conflictLines(deal)} | |
| 131 | 132 | <ol class="dates">${dates}</ol> |
| 132 | 133 | </section> |
| 133 | 134 | <section class="card" id="parties"> |
src/pages/sheet.ts +9
| @@ -11,6 +11,7 @@ import { PARTY_LABEL } from "../deadlines.ts"; | ||
| 11 | 11 | import { agent } from "../env.ts"; |
| 12 | 12 | import { escape } from "../http.ts"; |
| 13 | 13 | import { memoizer, print } from "../memo.ts"; |
| 14 | import { conflictLine } from "../order.ts"; | |
| 14 | 15 | import { draftsFor, MOMENT_LABEL, MOMENTS, type Draft } from "../reminders.ts"; |
| 15 | 16 | import type { Who } from "../who.ts"; |
| 16 | 17 | import { owner } from "../week.ts"; |
| @@ -52,6 +53,13 @@ export function owedBy(deal: DealView, d: DeadlineView): string { | ||
| 52 | 53 | : `<b>${escape(name)}</b> <span class="muted">· ${escape(role)}</span>`; |
| 53 | 54 | } |
| 54 | 55 | |
| 56 | /** One line per flagged date, as words: the sheet of a flagged date shows its own, the closing sheet all of them. */ | |
| 57 | export const conflictLines = (deal: DealView, d?: DeadlineView): string => | |
| 58 | deal.conflicts | |
| 59 | .filter((c) => d === undefined || d.kind === "closing" || c.deadline_id === d.id) | |
| 60 | .map((c) => `<p class="conflict" role="note"><b>Out of order:</b> ${escape(conflictLine(c))}</p>`) | |
| 61 | .join(""); | |
| 62 | ||
| 55 | 63 | const hidden = (fields: Record<string, string | number>): string => |
| 56 | 64 | Object.entries(fields) |
| 57 | 65 | .map(([k, v]) => `<input type="hidden" name="${k}" value="${escape(String(v))}">`) |
| @@ -179,6 +187,7 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: | ||
| 179 | 187 | <button class="button button-quiet" popovertarget="${id}" popovertargetaction="hide" aria-label="Close">✕</button> |
| 180 | 188 | </header> |
| 181 | 189 | <section><h3>Who owes what</h3><p>${owedBy(deal, d)}</p>${d.what === "" ? "" : `<p>${escape(d.what)}</p>`}</section> |
| 190 | ${conflictLines(deal, d)} | |
| 182 | 191 | ${moves} |
| 183 | 192 | <section><h3>Reminders</h3>${reminders}</section> |
| 184 | 193 | ${actions} |
src/routes.ts +20 −2
| @@ -46,6 +46,7 @@ import { | ||
| 46 | 46 | createDeal, |
| 47 | 47 | deleteDeal, |
| 48 | 48 | getDeal, |
| 49 | withConflicts, | |
| 49 | 50 | listDeals, |
| 50 | 51 | markDone, |
| 51 | 52 | mayOpen, |
| @@ -184,6 +185,21 @@ export const DEAL: Schema = { | ||
| 184 | 185 | }, |
| 185 | 186 | }, |
| 186 | 187 | }, |
| 188 | conflicts: { | |
| 189 | type: "array", | |
| 190 | description: | |
| 191 | "Open dates (not Closing) due on or after the open Closing date: a slipped contingency. Empty when the deal is in order or closed.", | |
| 192 | items: { | |
| 193 | type: "object", | |
| 194 | properties: { | |
| 195 | deadline_id: { type: "integer" }, | |
| 196 | label: { type: "string" }, | |
| 197 | due: DATE, | |
| 198 | closing: DATE, | |
| 199 | }, | |
| 200 | required: ["deadline_id", "label", "due", "closing"], | |
| 201 | }, | |
| 202 | }, | |
| 187 | 203 | declined: { |
| 188 | 204 | type: "array", |
| 189 | 205 | items: { |
| @@ -519,7 +535,8 @@ export const routes: readonly Route[] = [ | ||
| 519 | 535 | const f = await form(c); |
| 520 | 536 | if (f instanceof Response) return f; |
| 521 | 537 | const id = Number(c.params.id); |
| 522 | return done(addDeadline(c.db, c.who, { dealId: id, label: f.label, due: f.due, owes: f.owes, what: f.what }), backTo(`/deals/${id}`), "Date added."); | |
| 538 | const added = addDeadline(c.db, c.who, { dealId: id, label: f.label, due: f.due, owes: f.owes, what: f.what }); | |
| 539 | return done(added, backTo(`/deals/${id}`), added.ok ? withConflicts(c.db, c.who, id, "Date added.") : undefined); | |
| 523 | 540 | }, |
| 524 | 541 | }, |
| 525 | 542 | { |
| @@ -577,7 +594,8 @@ export const routes: readonly Route[] = [ | ||
| 577 | 594 | handle: async (c) => { |
| 578 | 595 | const f = await form(c); |
| 579 | 596 | if (f instanceof Response) return f; |
| 580 | return done(moveDeadline(c.db, c.who, { id: Number(c.params.id), due: f.due, reason: f.reason }), backTo(f.to), "Date moved; nothing else did."); | |
| 597 | const moved = moveDeadline(c.db, c.who, { id: Number(c.params.id), due: f.due, reason: f.reason }); | |
| 598 | return done(moved, backTo(f.to), moved.ok ? withConflicts(c.db, c.who, moved.value.deal_id, "Date moved; nothing else did.") : undefined); | |
| 581 | 599 | }, |
| 582 | 600 | }, |
| 583 | 601 | { |
src/server.test.ts +2 −1
| @@ -1142,7 +1142,8 @@ test("a moved date's Date changed notice is sent, declined and undone through th | ||
| 1142 | 1142 | expect((await form(`/deadlines/${insp.id}/move`, { due: "2026-12-01", reason: "Inspector away", to: "/" })).status).toBe(303); |
| 1143 | 1143 | const [buyer, seller] = [deal.parties.find((p) => p.role === "buyer")!, deal.parties.find((p) => p.role === "seller")!]; |
| 1144 | 1144 | const ask = (party: { id: number }) => ({ deadline: String(insp.id), party: String(party.id), moment: "moved", to: "/" }); |
| 1145 | const page = await (await api("/", {}, editor)).text(); | |
| 1145 | // The clock carries no sheets (they load on demand); the notice is under Reminders on the date's sheet. | |
| 1146 | const page = await (await api(`/deals/${id}/sheets`, {}, editor)).text(); | |
| 1146 | 1147 | expect(page).toContain("Date changed"); |
| 1147 | 1148 | // The page's forms: send with edited words, decline, undo. |
| 1148 | 1149 | expect((await form("/reminders", { ...ask(buyer), subject: "New date", body: "Moved to Dec 1." })).status).toBe(303); |
src/terminal.test.ts +41
| @@ -479,6 +479,47 @@ test("P lists each person once with the dates they owe across deals; a guest is | ||
| 479 | 479 | expect(lines(guest).join("\n")).not.toContain("Lena Lender"); |
| 480 | 480 | }); |
| 481 | 481 | |
| 482 | test("the deal view lists a date that falls after closing, in words", () => { | |
| 483 | const other = createDeal(db, alice, { | |
| 484 | address: "3 Fig Ct", | |
| 485 | buyer: "B", | |
| 486 | seller: "S", | |
| 487 | contractDate: today(), | |
| 488 | closingDate: addDays(today(), 30), | |
| 489 | }); | |
| 490 | if (!other.ok) throw new Error(other.message); | |
| 491 | const late = addDeadline(db, alice, { dealId: other.value.id, label: "Rate lock", due: addDays(today(), 35), owes: "buyer" }); | |
| 492 | expect(late.ok).toBe(true); | |
| 493 | const t = terminal(db, alice, context); | |
| 494 | goTo(t, "Rate lock — 3 Fig Ct"); | |
| 495 | t.press("o"); | |
| 496 | expect(lines(t).join("\n")).toContain("! Rate lock ("); | |
| 497 | expect(lines(t).join("\n")).toContain("now falls after closing"); | |
| 498 | }); | |
| 499 | ||
| 500 | test("m past closing moves the date and the status line names the conflict; a is the same", () => { | |
| 501 | const other = createDeal(db, alice, { | |
| 502 | address: "5 Gum Rd", | |
| 503 | buyer: "B", | |
| 504 | seller: "S", | |
| 505 | contractDate: today(), | |
| 506 | closingDate: addDays(today(), 30), | |
| 507 | }); | |
| 508 | if (!other.ok) throw new Error(other.message); | |
| 509 | const t = terminal(db, alice, context); | |
| 510 | goTo(t, "Financing contingency ends — 5 Gum Rd"); | |
| 511 | const past = addDays(today(), 33); | |
| 512 | press(t, "m", `${past}\r`, "Lender slow\r"); | |
| 513 | const moved = lines(t).join("\n"); | |
| 514 | expect(moved).toContain("Moved Financing contingency ends"); | |
| 515 | expect(moved).toContain("now falls after closing"); | |
| 516 | expect(getDeal(db, alice, { id: other.value.id }).ok).toBe(true); | |
| 517 | goTo(t, "Closing — 5 Gum Rd"); | |
| 518 | t.press("o"); | |
| 519 | press(t, "a", "Survey\r", `${past}\r`, "buyer\r", "\r"); | |
| 520 | expect(lines(t).join("\n")).toContain("Survey ("); | |
| 521 | }); | |
| 522 | ||
| 482 | 523 | test("a moved date's Date changed notice is on the reminders list; s sends it and the sent list reads its date", () => { |
| 483 | 524 | const made2 = createDeal(db, alice, { address: "31 Moved Way", buyer: "Bea Buyer", seller: "Sid Seller", contractDate: today(), closingDate: addDays(today(), 45) }); |
| 484 | 525 | if (!made2.ok) throw new Error(made2.message); |
src/terminal.ts +7 −3
| @@ -38,6 +38,7 @@ import { | ||
| 38 | 38 | plannedDates, |
| 39 | 39 | type NewDeal, |
| 40 | 40 | moveDeadline, |
| 41 | withConflicts, | |
| 41 | 42 | removeDeadline, |
| 42 | 43 | removeParty, |
| 43 | 44 | sendReminder, |
| @@ -49,6 +50,7 @@ import { | ||
| 49 | 50 | } from "./deals.ts"; |
| 50 | 51 | import { find, FIND_MAX, query } from "./find.ts"; |
| 51 | 52 | import { mayRestore, restoreSamples } from "./actions.ts"; |
| 53 | import { conflictLine } from "./order.ts"; | |
| 52 | 54 | import { PARTY_LABEL, PARTY_ROLES, type PartyRole } from "./deadlines.ts"; |
| 53 | 55 | import { drafts, MOMENT_LABEL, pending, unsent, type Agent, type Draft } from "./reminders.ts"; |
| 54 | 56 | import type { Result } from "./result.ts"; |
| @@ -146,7 +148,8 @@ export function terminal( | ||
| 146 | 148 | ? dateRows().length + (openDeal()?.parties.length ?? 0) |
| 147 | 149 | : dateRows().length; |
| 148 | 150 | |
| 149 | const report = <T>(result: Result<T>, success: string): string => (result.ok ? success : result.message); | |
| 151 | const report = <T>(result: Result<T>, success: string | (() => string)): string => | |
| 152 | result.ok ? (typeof success === "string" ? success : success()) : result.message; | |
| 150 | 153 | /** Only someone who may work the deal is asked to type anything. */ |
| 151 | 154 | const ask = (deal: DealView, steps: string[], finish: Prompt["finish"], max?: number): void => { |
| 152 | 155 | if (!canChange(me, deal)) { |
| @@ -168,7 +171,7 @@ export function terminal( | ||
| 168 | 171 | if (key === "u") said = report(markDone(db, me, { id: date.id, done: false }), `Reopened: ${date.label}, ${deal.address}.`); |
| 169 | 172 | if (key === "m") |
| 170 | 173 | ask(deal, [`New date for ${date.label} (YYYY-MM-DD, now ${date.due})`, "Why it moved"], ([due, reason]) => |
| 171 | report(moveDeadline(db, me, { id: date.id, due, reason }), `Moved ${date.label} to ${isDate(due) ? spoken(due!) : due}; nothing else moved.`), | |
| 174 | report(moveDeadline(db, me, { id: date.id, due, reason }), () => withConflicts(db, me, deal.id, `Moved ${date.label} to ${isDate(due) ? spoken(due!) : due}; nothing else moved.`)), | |
| 172 | 175 | ); |
| 173 | 176 | if ((key === "o" || key === "\r") && view === "dates") { |
| 174 | 177 | view = "deal"; |
| @@ -208,7 +211,7 @@ export function terminal( | ||
| 208 | 211 | } |
| 209 | 212 | if (key === "a") |
| 210 | 213 | ask(deal, ["What is the date (e.g. HOA review ends)", "Date (YYYY-MM-DD)", `Owed by (${PARTY_ROLES.join(", ")})`, "Details (optional)"], ([label, due, owes, what]) => |
| 211 | report(addDeadline(db, me, { dealId: deal.id, label, due, owes, what }), `Added ${label}.`), | |
| 214 | report(addDeadline(db, me, { dealId: deal.id, label, due, owes, what }), () => withConflicts(db, me, deal.id, `Added ${label}.`)), | |
| 212 | 215 | ); |
| 213 | 216 | if (key === "p") |
| 214 | 217 | ask(deal, [`Role (${PARTY_ROLES.join(", ")})`, "Name", "Email or phone (optional)"], ([role, name, contact]) => |
| @@ -522,6 +525,7 @@ export function terminal( | ||
| 522 | 525 | else { |
| 523 | 526 | lines.push(bold(deal.address), ...(deal.closed ? [bold(`Closed on ${spoken(closedOn(deal))}`)] : []), dim(`under contract ${spoken(deal.contract_date)} · closes ${spoken(deal.closing)}, ${relative(deal.closing, day)}`), ""); |
| 524 | 527 | deal.deadlines.forEach((date, i) => lines.push(dateLine({ deal, date }, i, false))); |
| 528 | if (deal.conflicts.length > 0) lines.push("", ...deal.conflicts.map((c) => tint("overdue", `! ${conflictLine(c)}`))); | |
| 525 | 529 | lines.push("", bold("Parties")); |
| 526 | 530 | deal.parties.forEach((p, i) => { |
| 527 | 531 | const at = deal.deadlines.length + i === cursor; |
static/app.css +14
| @@ -891,6 +891,20 @@ a.marker { | ||
| 891 | 891 | text-decoration: none; |
| 892 | 892 | } |
| 893 | 893 | |
| 894 | /* A date that falls on or after closing: a words-first line, and a mark on its marker. */ | |
| 895 | .conflict { | |
| 896 | margin: var() 0; | |
| 897 | color: var(); | |
| 898 | } | |
| 899 | .marker[data-conflict]::after { | |
| 900 | content: "!"; | |
| 901 | position: absolute; | |
| 902 | top: 0; | |
| 903 | right: 0; | |
| 904 | font-weight: 700; | |
| 905 | line-height: 1; | |
| 906 | } | |
| 907 | ||
| 894 | 908 | /* On paper: only the client timeline changes — black on white, no tools, no row split. */ |
| 895 | 909 | @media print { |
| 896 | 910 | .timeline-page { |
new above
offline
Only the deal view shows the conflict. The move/add handlers in this file should append conflictLine for the deal's conflicts to the status they set, so the terminal tells the agent at move time like the page does.