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

Merged opened this

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

Merged

mason/deal-clock:mason/58-a-date-that-falls-on-or-after-closing-is → main 6 commits fork 1 thread · 1 unresolved

  • Merged. mason/58-a-date-that-falls-on-or-after-closing-is was merged into main as 0fdfa2c.

Review

Sign in to review this change.
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
7777 made it. No other date moves. A *Date changed* notice is drafted for each
7878 party the date reminds, naming the old and the new date (not the reason);
7979 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.
8184 6. **See a date that was moved.** On 9 Orchard Row, open the appraisal
8285 marker. The sheet shows where it moved from and to, with the reason
8386 the appraiser gave.
contract/openapi.json +29
@@ -1146,6 +1146,35 @@
11461146 }
11471147 }
11481148 },
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 },
11491178 "declined": {
11501179 "type": "array",
11511180 "items": {
docs/TECHNICAL.md +2
@@ -225,3 +225,5 @@ it does is `src/terminal.ts`, which `src/terminal.test.ts` drives key by key.
225225 The forge sets `PORT`, `FORGE_APP_DATA`, `FORGE_APP_ENV` (`production` or
226226 `preview`), `FORGE_APP_URL`, `FORGE_APP_COMMIT`, `FORGE_APP_SSH` and
227227 `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 {
2121 } from "./deadlines.ts";
2222 import { agent as defaultAgent, LENGTH_MAX, standard } from "./env.ts";
2323 import { emit } from "./live.ts";
24 import { conflictLine, conflicts, type Conflict } from "./order.ts";
2425 import { draftsFor, moveKey, type Agent, type Draft } from "./reminders.ts";
2526 import { audited, fail, ok, refuse, type Result } from "./result.ts";
2627 import type { Who } from "./who.ts";
@@ -117,6 +118,8 @@ export interface DealView extends Deal {
117118 readonly deadlines: readonly DeadlineView[];
118119 readonly sent: readonly Sent[];
119120 readonly declined: readonly Declined[];
121 /** Open dates due on or after the open closing date (`order.ts`). */
122 readonly conflicts: readonly Conflict[];
120123 }
121124
122125 export type Moment = "before" | "day_of" | "late" | "moved";
@@ -190,6 +193,7 @@ function assemble(deal: Deal, rows: Children): DealView {
190193 })),
191194 sent: rows.sent,
192195 declined: rows.declined,
196 conflicts: conflicts(rows.deadlines),
193197 };
194198 }
195199
@@ -285,6 +289,18 @@ function viewMany(db: Database, where: string, params: string[]): DealView[] {
285289 );
286290 }
287291
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
288304 export function listDeals(db: Database, who: Who): Result<DealView[]> {
289305 const may = permit(who, "deal", "list");
290306 if (may === "no")
src/mcp.ts +12 −5
@@ -9,9 +9,11 @@
99 import type { Database } from "bun:sqlite";
1010 import { restoreSamples, type Result } from "./actions.ts";
1111 import { today } from "./dates.ts";
12 import { ok } from "./result.ts";
1213 import { DEFAULT_LENGTHS, PARTY_ROLES } from "./deadlines.ts";
1314 import {
1415 addDeadline,
16 conflictsOf,
1517 addParty,
1618 createDeal,
1719 deleteDeal,
@@ -61,7 +63,7 @@ export const tools: readonly Tool[] = [
6163 },
6264 {
6365 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.",
6567 inputSchema: { type: "object", properties: { id: { type: "integer" } }, required: ["id"] },
6668 run: (db, who, args) => getDeal(db, who, { id: Number(args.id) }),
6769 },
@@ -125,7 +127,7 @@ export const tools: readonly Tool[] = [
125127 },
126128 {
127129 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.",
129131 inputSchema: {
130132 type: "object",
131133 properties: {
@@ -135,7 +137,10 @@ export const tools: readonly Tool[] = [
135137 },
136138 required: ["id", "due", "reason"],
137139 },
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 },
139144 },
140145 {
141146 name: "send_reminder",
@@ -234,8 +239,10 @@ export const tools: readonly Tool[] = [
234239 },
235240 required: ["deal_id", "label", "due", "owes"],
236241 },
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 },
239246 },
240247 {
241248 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 {
6060 const d = deal.deadlines[i]!;
6161 const u = urgency(d.due, on, d.done_at !== null);
6262 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>`;
6465 })
6566 .join("");
6667 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>
6869 <div class="track" style="height:calc(${height} * 3rem)">${markers}</div>
6970 </li>`;
7071 }
src/pages/deal.ts +2 −1
@@ -12,7 +12,7 @@ import { escape } from "../http.ts";
1212 import { MOMENT_LABEL } from "../reminders.ts";
1313 import type { Who } from "../who.ts";
1414 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";
1616
1717 const roleOptions = (selected?: string): string =>
1818 PARTY_ROLES.map(
@@ -128,6 +128,7 @@ export function dealPage(input: {
128128 <div id="deal" data-live="deal.changed">
129129 <section class="card">
130130 <h2>Dates</h2>
131 ${conflictLines(deal)}
131132 <ol class="dates">${dates}</ol>
132133 </section>
133134 <section class="card" id="parties">
src/pages/sheet.ts +9
@@ -11,6 +11,7 @@ import { PARTY_LABEL } from "../deadlines.ts";
1111 import { agent } from "../env.ts";
1212 import { escape } from "../http.ts";
1313 import { memoizer, print } from "../memo.ts";
14 import { conflictLine } from "../order.ts";
1415 import { draftsFor, MOMENT_LABEL, MOMENTS, type Draft } from "../reminders.ts";
1516 import type { Who } from "../who.ts";
1617 import { owner } from "../week.ts";
@@ -52,6 +53,13 @@ export function owedBy(deal: DealView, d: DeadlineView): string {
5253 : `<b>${escape(name)}</b> <span class="muted">· ${escape(role)}</span>`;
5354 }
5455
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
5563 const hidden = (fields: Record<string, string | number>): string =>
5664 Object.entries(fields)
5765 .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:
179187 <button class="button button-quiet" popovertarget="${id}" popovertargetaction="hide" aria-label="Close">✕</button>
180188 </header>
181189 <section><h3>Who owes what</h3><p>${owedBy(deal, d)}</p>${d.what === "" ? "" : `<p>${escape(d.what)}</p>`}</section>
190 ${conflictLines(deal, d)}
182191 ${moves}
183192 <section><h3>Reminders</h3>${reminders}</section>
184193 ${actions}
src/routes.ts +20 −2
@@ -46,6 +46,7 @@ import {
4646 createDeal,
4747 deleteDeal,
4848 getDeal,
49 withConflicts,
4950 listDeals,
5051 markDone,
5152 mayOpen,
@@ -184,6 +185,21 @@ export const DEAL: Schema = {
184185 },
185186 },
186187 },
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 },
187203 declined: {
188204 type: "array",
189205 items: {
@@ -519,7 +535,8 @@ export const routes: readonly Route[] = [
519535 const f = await form(c);
520536 if (f instanceof Response) return f;
521537 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);
523540 },
524541 },
525542 {
@@ -577,7 +594,8 @@ export const routes: readonly Route[] = [
577594 handle: async (c) => {
578595 const f = await form(c);
579596 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);
581599 },
582600 },
583601 {
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
11421142 expect((await form(`/deadlines/${insp.id}/move`, { due: "2026-12-01", reason: "Inspector away", to: "/" })).status).toBe(303);
11431143 const [buyer, seller] = [deal.parties.find((p) => p.role === "buyer")!, deal.parties.find((p) => p.role === "seller")!];
11441144 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();
11461147 expect(page).toContain("Date changed");
11471148 // The page's forms: send with edited words, decline, undo.
11481149 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
479479 expect(lines(guest).join("\n")).not.toContain("Lena Lender");
480480 });
481481
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
482523 test("a moved date's Date changed notice is on the reminders list; s sends it and the sent list reads its date", () => {
483524 const made2 = createDeal(db, alice, { address: "31 Moved Way", buyer: "Bea Buyer", seller: "Sid Seller", contractDate: today(), closingDate: addDays(today(), 45) });
484525 if (!made2.ok) throw new Error(made2.message);
src/terminal.ts +7 −3
@@ -38,6 +38,7 @@ import {
3838 plannedDates,
3939 type NewDeal,
4040 moveDeadline,
41 withConflicts,
4142 removeDeadline,
4243 removeParty,
4344 sendReminder,
@@ -49,6 +50,7 @@ import {
4950 } from "./deals.ts";
5051 import { find, FIND_MAX, query } from "./find.ts";
5152 import { mayRestore, restoreSamples } from "./actions.ts";
53 import { conflictLine } from "./order.ts";
5254 import { PARTY_LABEL, PARTY_ROLES, type PartyRole } from "./deadlines.ts";
5355 import { drafts, MOMENT_LABEL, pending, unsent, type Agent, type Draft } from "./reminders.ts";
5456 import type { Result } from "./result.ts";
@@ -146,7 +148,8 @@ export function terminal(
146148 ? dateRows().length + (openDeal()?.parties.length ?? 0)
147149 : dateRows().length;
148150
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;
150153 /** Only someone who may work the deal is asked to type anything. */
151154 const ask = (deal: DealView, steps: string[], finish: Prompt["finish"], max?: number): void => {
152155 if (!canChange(me, deal)) {
@@ -168,7 +171,7 @@ export function terminal(
168171 if (key === "u") said = report(markDone(db, me, { id: date.id, done: false }), `Reopened: ${date.label}, ${deal.address}.`);
169172 if (key === "m")
170173 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.`)),
172175 );
173176 if ((key === "o" || key === "\r") && view === "dates") {
174177 view = "deal";
@@ -208,7 +211,7 @@ export function terminal(
208211 }
209212 if (key === "a")
210213 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}.`)),
212215 );
213216 if (key === "p")
214217 ask(deal, [`Role (${PARTY_ROLES.join(", ")})`, "Name", "Email or phone (optional)"], ([role, name, contact]) =>
@@ -522,6 +525,7 @@ export function terminal(
522525 else {
523526 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)}`), "");
outdated

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.

524527 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)}`)));
525529 lines.push("", bold("Parties"));
526530 deal.parties.forEach((p, i) => {
527531 const at = deal.deadlines.length + i === cursor;
static/app.css +14
@@ -891,6 +891,20 @@ a.marker {
891891 text-decoration: none;
892892 }
893893
894 /* A date that falls on or after closing: a words-first line, and a mark on its marker. */
895 .conflict {
896 margin: var(--space-2) 0;
897 color: var(--color-overdue);
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
894908 /* On paper: only the client timeline changes — black on white, no tools, no row split. */
895909 @media print {
896910 .timeline-page {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs