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

A contingency the buyer waives is marked Waived, not done or removed, so its reminders stop and the record shows it was given up on purpose #99

Merged opened this

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

Merged

mason/deal-clock:mason/96-a-contingency-the-buyer-waives-is-marked → main 1 commit fork

  • Merged. mason/96-a-contingency-the-buyer-waives-is-marked was merged into main as 03381d0.

Review

Sign in to review this change.
32 files changed +605 −68
README.md +4
@@ -105,6 +105,10 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture
105105 the appraiser gave.
106106 7. **Mark a date done.** On Alder Lane, open a coming date and tap Mark
107107 done. The marker turns grey and its reminders stop. Reopen puts it back.
108 When the buyer gives a contingency up on purpose, tap Waive instead (it
109 asks once): on 2210 Juniper Court the appraisal is already waived, grey
110 and marked Waived, still counted as settled, with no reminders; Un-waive
111 brings it back as it was.
108112 8. **Add a party.** Tap the address 2210 Juniper Court to open the deal's
109113 page. It lists every date and every party. Under "Add a party" pick a
110114 role (the title company, say), type a name and an email or phone, and
contract/openapi.json +172
@@ -674,6 +674,20 @@
674674 "null"
675675 ]
676676 },
677 "waived_at": {
678 "type": [
679 "string",
680 "null"
681 ],
682 "description": "When the buyer waived this date on purpose; null while it stands. A waived date is settled: no reminders, flags or conflicts."
683 },
684 "waived_by": {
685 "type": [
686 "string",
687 "null"
688 ],
689 "description": "Who recorded the waiver."
690 },
677691 "moves": {
678692 "type": "array",
679693 "items": {
@@ -1678,6 +1692,150 @@
16781692 }
16791693 }
16801694 },
1695 "/api/deals/{id}/deadlines/{deadline}/waive": {
1696 "post": {
1697 "summary": "Waive a date the buyer gave up on purpose: it stays on the deal, settled (counted in progress), and drafts no more reminders, follow-up, business-day flag or after-closing conflict; its waiting reminders leave the review. The day and who waived it are kept. Closing is refused (422), as is a date already done or waived.",
1698 "operationId": "postApiDealsIdDeadlinesDeadlineWaive",
1699 "parameters": [
1700 {
1701 "name": "id",
1702 "in": "path",
1703 "required": true,
1704 "schema": {
1705 "type": "integer"
1706 }
1707 },
1708 {
1709 "name": "deadline",
1710 "in": "path",
1711 "required": true,
1712 "schema": {
1713 "type": "integer"
1714 }
1715 }
1716 ],
1717 "responses": {
1718 "200": {
1719 "description": "Waive a date the buyer gave up on purpose: it stays on the deal, settled (counted in progress), and drafts no more reminders, follow-up, business-day flag or after-closing conflict; its waiting reminders leave the review. The day and who waived it are kept. Closing is refused (422), as is a date already done or waived.",
1720 "content": {
1721 "application/json": {
1722 "schema": {
1723 "type": "object",
1724 "properties": {
1725 "id": {
1726 "type": "integer"
1727 },
1728 "waived_at": {
1729 "type": [
1730 "string",
1731 "null"
1732 ]
1733 },
1734 "waived_by": {
1735 "type": [
1736 "string",
1737 "null"
1738 ]
1739 }
1740 },
1741 "required": [
1742 "id",
1743 "waived_at",
1744 "waived_by"
1745 ]
1746 }
1747 }
1748 }
1749 },
1750 "default": {
1751 "description": "{ error, message }: why not",
1752 "content": {
1753 "application/json": {
1754 "schema": {
1755 "$ref": "#/components/schemas/Error"
1756 }
1757 }
1758 }
1759 }
1760 },
1761 "x-contract": {
1762 "resource": "deal",
1763 "verb": "update",
1764 "least": "user"
1765 }
1766 },
1767 "delete": {
1768 "summary": "Un-waive a date: it comes back open with its date unchanged, and its reminders are drafted again. Refused (422) when it is not waived.",
1769 "operationId": "deleteApiDealsIdDeadlinesDeadlineWaive",
1770 "parameters": [
1771 {
1772 "name": "id",
1773 "in": "path",
1774 "required": true,
1775 "schema": {
1776 "type": "integer"
1777 }
1778 },
1779 {
1780 "name": "deadline",
1781 "in": "path",
1782 "required": true,
1783 "schema": {
1784 "type": "integer"
1785 }
1786 }
1787 ],
1788 "responses": {
1789 "200": {
1790 "description": "Un-waive a date: it comes back open with its date unchanged, and its reminders are drafted again. Refused (422) when it is not waived.",
1791 "content": {
1792 "application/json": {
1793 "schema": {
1794 "type": "object",
1795 "properties": {
1796 "id": {
1797 "type": "integer"
1798 },
1799 "waived_at": {
1800 "type": [
1801 "string",
1802 "null"
1803 ]
1804 },
1805 "waived_by": {
1806 "type": [
1807 "string",
1808 "null"
1809 ]
1810 }
1811 },
1812 "required": [
1813 "id",
1814 "waived_at",
1815 "waived_by"
1816 ]
1817 }
1818 }
1819 }
1820 },
1821 "default": {
1822 "description": "{ error, message }: why not",
1823 "content": {
1824 "application/json": {
1825 "schema": {
1826 "$ref": "#/components/schemas/Error"
1827 }
1828 }
1829 }
1830 }
1831 },
1832 "x-contract": {
1833 "resource": "deal",
1834 "verb": "update",
1835 "least": "user"
1836 }
1837 }
1838 },
16811839 "/api/audit": {
16821840 "get": {
16831841 "summary": "The audit trail, newest first; `before` pages back by id.",
@@ -1991,6 +2149,20 @@
19912149 "null"
19922150 ]
19932151 },
2152 "waived_at": {
2153 "type": [
2154 "string",
2155 "null"
2156 ],
2157 "description": "When the buyer waived this date on purpose; null while it stands. A waived date is settled: no reminders, flags or conflicts."
2158 },
2159 "waived_by": {
2160 "type": [
2161 "string",
2162 "null"
2163 ],
2164 "description": "Who recorded the waiver."
2165 },
19942166 "moves": {
19952167 "type": "array",
19962168 "items": {
docs/TECHNICAL.md +10 −2
@@ -23,6 +23,14 @@ Removing a party or a date drops the reminders not yet sent; reminders already
2323 marked sent stay on record. Over the API: `PATCH` or `DELETE
2424 /api/deals/:id/parties/:party` and `DELETE /api/deals/:id/deadlines/:deadline`.
2525
26 A date the buyer waives (any but Closing) keeps its place on the deal with
27 `waived_at` and `waived_by` set, and is settled: progress counts it, and it
28 drafts no reminders, follow-up, business-day flag or after-closing conflict.
29 `POST /deadlines/:id/waive` (the page; waiving needs `confirm=yes`),
30 `POST` and `DELETE /api/deals/:id/deadlines/:deadline/waive` (waive, un-waive),
31 the MCP tool `waive_date` and `W` in the terminal all call `waiveDate`, an
32 update of the deal, audited as `date.waive`.
33
2634 Lead time: every date has `lead_days` (1 to 30, column `deadline.lead_days`,
2735 default 3; new Financing dates and the sample deals start at 7, new Earnest money
2836 deposit dates at 1, see `leadOf` in `src/deadlines.ts`). The deposit is the
@@ -122,7 +130,7 @@ tools at `POST /mcp` (`list_deals`, `get_deal`, `client_timeline`, `reminders_to
122130 `open_deal`, `add_date`, `update_address`, `add_party`, `edit_party`, `remove_party`,
123131 `remove_date` — custom dates only — `remove_deal` — its author or an admin —
124132 `mark_done` — with `done: false` to
125 reopen a date — `move_date`, `set_reminder_lead`, `amend_deal` (several dates, one reason), `send_reminder`, `restore_samples` — admin only: puts the
133 reopen a date — `waive_date` — with `waived: false` to un-waive it — `move_date`, `set_reminder_lead`, `amend_deal` (several dates, one reason), `send_reminder`, `restore_samples` — admin only: puts the
126134 four sample deals back and leaves every other deal alone). `send_reminder` takes an
127135 optional `subject` and `body` to send edited words; without them the draft
128136 goes as it is.
@@ -131,7 +139,7 @@ The terminal does the page's work too. It opens on every open date, soonest
131139 first: `n` opens a new deal (address, buyer, seller, contract date, closing
132140 date; the standard lengths do the rest; `c` asks the same five questions and
133141 lists every date `n` would create, writing nothing), `x` marks the date under the cursor
134 done, `u` reopens it, `m` moves it (the new date, then the reason), `o` opens
142 done, `W` waives it (a contingency the buyer gave up; `u` un-waives), `u` reopens it, `m` moves it (the new date, then the reason), `o` opens
135143 its deal — where `a` adds a date,
136144 `p` adds a party, `e` edits the party under the cursor (the cursor walks the
137145 dates, then the parties), `X` removes the date or party under it after you
src/activity.ts +1
@@ -17,6 +17,7 @@ const WORDS: Readonly<Record<string, string>> = {
1717 "reminder.undo": "undid a declined reminder",
1818 "date.move": "moved a date",
1919 "date.done": "marked a date done",
20 "date.waive": "waived a date",
2021 "date.lead": "changed when a date's reminder goes out",
2122 "date.add": "added a date",
2223 "date.remove": "removed a date",
src/dates.ts +5 −1
@@ -150,7 +150,7 @@ export function relative(date: string, from: string): string {
150150 return n > 0 ? `in ${n} days` : `${-n} days ago`;
151151 }
152152
153 export type Urgency = "done" | "overdue" | "soon" | "later";
153 export type Urgency = "done" | "waived" | "overdue" | "soon" | "later";
154154 /** How a deadline looks on the clock: grey when done, red past due, amber within three days. */
155155 export function urgency(due: string, on: string, done: boolean): Urgency {
156156 if (done) return "done";
@@ -159,3 +159,7 @@ export function urgency(due: string, on: string, done: boolean): Urgency {
159159 if (n <= 3) return "soon";
160160 return "later";
161161 }
162
163 /** `urgency` of a stored date: a waived one is grey and its own word, whatever its day. */
164 export const urgencyOf = (d: { due: string; done_at: string | null; waived_at: string | null }, on: string): Urgency =>
165 d.waived_at !== null ? "waived" : urgency(d.due, on, d.done_at !== null);
src/db.ts +3
@@ -371,6 +371,9 @@ export const migrations: string[] = [
371371 DROP TABLE reminder_declined;
372372 ALTER TABLE reminder_declined_new RENAME TO reminder_declined;
373373 CREATE INDEX reminder_declined_deal ON reminder_declined (deal_id)`,
374 // A date the buyer gave up on purpose: neither done nor gone. Who waived it is kept with the day.
375 `ALTER TABLE deadline ADD COLUMN waived_at TEXT`,
376 `ALTER TABLE deadline ADD COLUMN waived_by TEXT`,
374377 ];
375378
376379 export function openDb(dir = dataDir): Database {
src/deadlines.ts +7
@@ -23,6 +23,13 @@ export const PARTY_LABEL: Readonly<Record<PartyRole, string>> = {
2323 title: "Title company",
2424 other_agent: "Other agent",
2525 };
26 /** A date is open until it is done or waived; only an open date drafts reminders, flags or conflicts. */
27 export const isOpen = (d: { done_at: string | null; waived_at: string | null }): boolean => d.done_at === null && d.waived_at === null;
28 /** Done or waived: nothing is left to do about it, and the progress line counts it. */
29 export const isSettled = (d: { done_at: string | null; waived_at: string | null }): boolean => !isOpen(d);
30 /** The kinds a buyer can give up: everything but Closing. */
31 export const isWaivable = (kind: string): boolean => kind !== "closing";
32
2633 export const isPartyRole = (v: unknown): v is PartyRole =>
2734 PARTY_ROLES.includes(v as PartyRole);
2835
src/deals.test.ts +1 −1
@@ -293,7 +293,7 @@ test("the book: every open date of every open deal, no done dates, no closed dea
293293 const stamp = new Date("2026-10-12T08:00:00Z");
294294 const count = (ics: string) => ics.split("BEGIN:VEVENT").length - 1;
295295 const openDates = (list: readonly DealView[]) =>
296 list.filter((d) => !d.closed).flatMap((d) => d.deadlines.filter((x) => x.done_at === null));
296 list.filter((d) => !d.closed).flatMap((d) => d.deadlines.filter((x) => x.done_at === null && x.waived_at === null));
297297 const before = book(deals, "clock.example", stamp);
298298 expect(count(before)).toBe(openDates(deals).length);
299299 expect(before.split("BEGIN:VALARM").length - 1).toBe(2 * openDates(deals).length);
src/deals.ts +40 −2
@@ -12,7 +12,9 @@ import { isBusinessDay, isDate, nextBusinessDay, today } from "./dates.ts";
1212 import {
1313 DEFAULT_LENGTHS,
1414 isClosed,
15 isOpen,
1516 isPartyRole,
17 isWaivable,
1618 KIND,
1719 LEAD_MAX,
1820 LEAD_MIN,
@@ -108,6 +110,9 @@ export interface Deadline {
108110 readonly owes: PartyRole;
109111 readonly what: string;
110112 readonly done_at: string | null;
113 /** When the buyer gave this date up on purpose, and who recorded it; null while it stands. */
114 readonly waived_at: string | null;
115 readonly waived_by: string | null;
111116 /** Days before it is due that its first reminder goes out. */
112117 readonly lead_days: number;
113118 }
@@ -212,7 +217,7 @@ function assemble(deal: Deal, rows: Children): DealView {
212217 deadlines: rows.deadlines.map((d) => ({
213218 ...d,
214219 moves: moves.filter((m) => m.deadline_id === d.id),
215 nonBusinessDay: d.done_at === null && !isBusinessDay(d.due) ? { next: nextBusinessDay(d.due) } : null,
220 nonBusinessDay: isOpen(d) && !isBusinessDay(d.due) ? { next: nextBusinessDay(d.due) } : null,
216221 })),
217222 sent: rows.sent.map((m) => withHref(m, rows.parties)),
218223 declined: rows.declined,
@@ -636,12 +641,45 @@ export function markDone(
636641 ): Result<Deadline> {
637642 const { dealId, found } = deadlineFor(db, who, input.id);
638643 if (!found.ok) return within(db, who, "date.done", dealId, found);
644 if (input.done && found.value.deadline.waived_at !== null)
645 return within(db, who, "date.done", dealId, fail("invalid", "This date was waived; un-waive it first."));
639646 db.query(
640647 "UPDATE deadline SET done_at = ?1 WHERE id = ?2",
641648 ).run(input.done ? new Date().toISOString() : null, input.id);
642649 return within(db, who, "date.done", dealId, ok(reread(db, input.id)));
643650 }
644651
652 /**
653 * Waive a date the buyer gave up on purpose (or take that back): it stays on
654 * the deal, settled, and drafts no more reminders. The day and who waived it
655 * are kept. Closing is never waivable, and a done date is not waived.
656 */
657 export function waiveDate(
658 db: Database,
659 who: Who,
660 input: { id: number; dealId?: number; waived: boolean },
661 ): Result<Deadline> {
662 const { dealId, found } = deadlineFor(db, who, input.id, input.dealId);
663 if (!found.ok) return within(db, who, "date.waive", dealId, found);
664 const { deadline } = found.value;
665 if (input.waived) {
666 if (!isWaivable(deadline.kind))
667 return within(db, who, "date.waive", dealId, fail("invalid", "Closing cannot be waived."));
668 if (deadline.done_at !== null)
669 return within(db, who, "date.waive", dealId, fail("invalid", "This date is already done; reopen it to waive it."));
670 if (deadline.waived_at !== null)
671 return within(db, who, "date.waive", dealId, fail("invalid", "This date is already waived."));
672 } else if (deadline.waived_at === null) {
673 return within(db, who, "date.waive", dealId, fail("invalid", "This date is not waived."));
674 }
675 db.query("UPDATE deadline SET waived_at = ?1, waived_by = ?2 WHERE id = ?3").run(
676 input.waived ? new Date().toISOString() : null,
677 input.waived ? authorOf(who).name : null,
678 input.id,
679 );
680 return within(db, who, "date.waive", dealId, ok(reread(db, input.id)));
681 }
682
645683 /** Whether `value` is a lead time: a whole number of days, 1 to 30. */
646684 const isLead = (value: unknown): value is number =>
647685 typeof value === "number" && Number.isInteger(value) && value >= LEAD_MIN && value <= LEAD_MAX;
@@ -708,7 +746,7 @@ export function amendment(deal: DealView, dates: unknown, reasonText: unknown):
708746 return { ok: false, field: "dates", message: "Give the dates as { date id: new date }." };
709747 const moves: { deadline: Deadline; to: string }[] = [];
710748 for (const [key, to] of Object.entries(dates)) {
711 const deadline = deal.deadlines.find((d) => String(d.id) === key && d.done_at === null);
749 const deadline = deal.deadlines.find((d) => String(d.id) === key && isOpen(d));
712750 if (deadline === undefined)
713751 return { ok: false, field: `due_${key}`, message: `Date ${key} is not an open date of this deal.` };
714752 if (!isDate(to))
src/ics.ts +4 −4
@@ -6,7 +6,7 @@
66 */
77
88 import { addDays } from "./dates.ts";
9 import { PARTY_LABEL } from "./deadlines.ts";
9 import { isOpen, PARTY_LABEL } from "./deadlines.ts";
1010 import type { DealView } from "./deals.ts";
1111 import { signOff, type Agent } from "./reminders.ts";
1212
@@ -43,7 +43,7 @@ const stampOf = (stamp: Date): string => stamp.toISOString().replace(/[-:]/g, ""
4343 function events(deal: DealView, host: string, now: string, openOnly: boolean): string[] {
4444 const lines: string[] = [];
4545 for (const d of deal.deadlines) {
46 if (openOnly && d.done_at !== null) continue;
46 if (openOnly && !isOpen(d)) continue;
4747 const owner = deal.parties.find((p) => p.role === d.owes);
4848 const who = owner === undefined ? PARTY_LABEL[d.owes] : `${owner.name} (${PARTY_LABEL[d.owes]})`;
4949 lines.push(
@@ -52,12 +52,12 @@ function events(deal: DealView, host: string, now: string, openOnly: boolean): s
5252 `DTSTAMP:${now}`,
5353 `DTSTART;VALUE=DATE:${compact(d.due)}`,
5454 `DTEND;VALUE=DATE:${compact(addDays(d.due, 1))}`,
55 `SUMMARY:${icsText(`${d.done_at === null ? "" : "Done: "}${d.label} — ${deal.address}`)}`,
55 `SUMMARY:${icsText(`${d.waived_at !== null ? "Waived: " : d.done_at === null ? "" : "Done: "}${d.label} — ${deal.address}`)}`,
5656 `DESCRIPTION:${icsText(`${who} owes: ${d.what || d.label}`)}`,
5757 "STATUS:CONFIRMED",
5858 "TRANSP:TRANSPARENT",
5959 );
60 if (d.done_at === null)
60 if (isOpen(d))
6161 lines.push(
6262 "BEGIN:VALARM",
6363 "ACTION:DISPLAY",
src/mcp.ts +11
@@ -22,6 +22,7 @@ import {
2222 getDeal,
2323 listDeals,
2424 markDone,
25 waiveDate,
2526 amendDeal,
2627 moveDeadline,
2728 removeDeadline,
@@ -130,6 +131,16 @@ export const tools: readonly Tool[] = [
130131 },
131132 run: (db, who, args) => markDone(db, who, { id: Number(args.id), done: args.done !== false }),
132133 },
134 {
135 name: "waive_date",
136 description: "Waive a date the buyer gave up on purpose (not Closing): it stays on the deal, settled, with no more reminders. Un-waive it with waived: false.",
137 inputSchema: {
138 type: "object",
139 properties: { id: { type: "integer" }, waived: { type: "boolean", default: true } },
140 required: ["id"],
141 },
142 run: (db, who, args) => waiveDate(db, who, { id: Number(args.id), waived: args.waived !== false }),
143 },
133144 {
134145 name: "move_date",
135146 description: "Move one date, and only that one, giving the reason. The answer lists conflicts: open dates now due on or after closing.",
src/order.test.ts +1
@@ -7,6 +7,7 @@ const d = (id: number, kind: string, due: string, done_at: string | null = null)
77 label: kind === "financing" ? "Financing" : kind === "closing" ? "Closing" : kind,
88 due,
99 done_at,
10 waived_at: null,
1011 });
1112
1213 test("an open date before closing is in order; on and after closing are flagged", () => {
src/order.ts +3 −1
@@ -5,6 +5,7 @@
55 */
66
77 import { short } from "./dates.ts";
8 import { isOpen } from "./deadlines.ts";
89
910 /** An open, non-closing date that falls on or after the closing date. */
1011 export interface Conflict {
@@ -20,6 +21,7 @@ interface Dated {
2021 readonly label: string;
2122 readonly due: string;
2223 readonly done_at: string | null;
24 readonly waived_at: string | null;
2325 }
2426
2527 /** 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. */
@@ -27,7 +29,7 @@ export function conflicts(deadlines: readonly Dated[]): Conflict[] {
2729 const closing = deadlines.find((d) => d.kind === "closing");
2830 if (closing === undefined || closing.done_at !== null) return [];
2931 return deadlines
30 .filter((d) => d.kind !== "closing" && d.done_at === null && d.due >= closing.due)
32 .filter((d) => d.kind !== "closing" && isOpen(d) && d.due >= closing.due)
3133 .map((d) => ({ deadline_id: d.id, label: d.label, due: d.due, closing: closing.due }));
3234 }
3335
src/pages/amend.ts +2 −1
@@ -5,6 +5,7 @@
55 * form comes back with what was typed and the field that was wrong.
66 */
77
8 import { isOpen } from "../deadlines.ts";
89 import type { DealView } from "../deals.ts";
910 import { escape } from "../http.ts";
1011
@@ -16,7 +17,7 @@ export interface AmendState {
1617 }
1718
1819 export function amendForm(deal: DealView, path: string, state?: AmendState): string {
19 const open = deal.deadlines.filter((d) => d.done_at === null);
20 const open = deal.deadlines.filter(isOpen);
2021 if (open.length === 0) return "";
2122 const { values = {}, problem } = state ?? {};
2223 const bad = (field: string): string =>
src/pages/clock.ts +6 −5
@@ -5,9 +5,9 @@
55 * clock, the reminders that go out today.
66 */
77
8 import { addDays, daysBetween, isWeekend, short, spoken, urgency } from "../dates.ts";
8 import { addDays, daysBetween, isWeekend, short, spoken, urgency, urgencyOf } from "../dates.ts";
99 import type { DealView } from "../deals.ts";
10 import { KIND } from "../deadlines.ts";
10 import { isOpen, KIND } from "../deadlines.ts";
1111 import { escape } from "../http.ts";
1212 import { agent as defaults } from "../env.ts";
1313 import { todaysDrafts, unsent, type Agent } from "../reminders.ts";
@@ -26,7 +26,7 @@ export function span(deals: readonly DealView[], on: string): { start: string; d
2626 let end = addDays(on, 21);
2727 for (const deal of deals)
2828 for (const d of deal.deadlines) {
29 if (d.done_at === null && d.due < addDays(start, 2)) start = addDays(d.due, -2);
29 if (isOpen(d) && d.due < addDays(start, 2)) start = addDays(d.due, -2);
3030 if (d.due > addDays(end, -4)) end = addDays(d.due, 4);
3131 }
3232 return { start, days: daysBetween(start, end) + 1 };
@@ -59,7 +59,7 @@ function drawLane(deal: DealView, start: string, on: string): string {
5959 const markers = placed
6060 .map(({ row, x, i }) => {
6161 const d = deal.deadlines[i]!;
62 const u = urgency(d.due, on, d.done_at !== null);
62 const u = urgencyOf(d, on);
6363 const tag = d.kind === "custom" ? d.label.split(" ")[0]! : KIND[d.kind].tag;
6464 const flagged = deal.conflicts.some((c) => c.deadline_id === d.id);
6565 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>`;
@@ -178,7 +178,7 @@ function render(input: {
178178 const closed = found
179179 .filter((deal) => deal.closed)
180180 .sort((a, b) => b.closing.localeCompare(a.closing) || b.id - a.id);
181 const open = deals.flatMap((deal) => deal.deadlines.filter((d) => d.done_at === null));
181 const open = deals.flatMap((deal) => deal.deadlines.filter(isOpen));
182182 const overdue = open.filter((d) => urgency(d.due, on, false) === "overdue").length;
183183 const soon = open.filter((d) => urgency(d.due, on, false) === "soon").length;
184184 const { start, days } = span(deals, on);
@@ -239,6 +239,7 @@ function render(input: {
239239 <li><span class="dot" data-u="soon"></span>Due within 3 days</li>
240240 <li><span class="dot" data-u="later"></span>Upcoming</li>
241241 <li><span class="dot" data-u="done"></span>Done</li>
242 <li><span class="dot" data-u="waived"></span>Waived</li>
242243 </ul>
243244 </section>
244245 ${closedCard}
src/pages/confirm.ts +3 −1
@@ -17,6 +17,8 @@ export function confirmRemove(input: {
1717 fields?: Readonly<Record<string, string>>;
1818 /** What the button's accessible name says it removes: "Yes, remove 77 Harbor View Dr". */
1919 name: string;
20 /** The button's words, when it is not a removal: "Yes, waive". */
21 yes?: string;
2022 small?: boolean;
2123 class?: string;
2224 }): string {
@@ -26,6 +28,6 @@ export function confirmRemove(input: {
2628 return `<details class="confirm${input.class === undefined ? "" : ` ${input.class}`}">
2729 <summary class="button button-quiet${input.small ? " button-small" : ""}">${escape(input.summary)}</summary>
2830 <p>${escape(input.goes)}</p>
29 <form method="post" action="${escape(input.action)}">${hidden}<button class="button" aria-label="${escape(input.name)}">Yes, remove</button></form>
31 <form method="post" action="${escape(input.action)}">${hidden}<button class="button" aria-label="${escape(input.name)}">${escape(input.yes ?? "Yes, remove")}</button></form>
3032 </details>`;
3133 }
src/pages/sheet.ts +29 −8
@@ -6,8 +6,8 @@
66 */
77
88 import { BODY_MAX, canChange, ROLL_REASON, REASON_MAX, SUBJECT_MAX, type DealView, type DeadlineView } from "../deals.ts";
9 import { relative, short, spoken, urgency, type Urgency } from "../dates.ts";
10 import { LEAD_MAX, LEAD_MIN, PARTY_LABEL } from "../deadlines.ts";
9 import { relative, short, spoken, urgencyOf, type Urgency } from "../dates.ts";
10 import { isOpen, isWaivable, LEAD_MAX, LEAD_MIN, PARTY_LABEL } from "../deadlines.ts";
1111 import { escape } from "../http.ts";
1212 import { confirmRemove } from "./confirm.ts";
1313 import { memoizer, print } from "../memo.ts";
@@ -31,6 +31,7 @@ export const opens = (deal: DealView, d: DeadlineView): string =>
3131
3232 export const URGENCY_LABEL: Readonly<Record<Urgency, string>> = {
3333 done: "Done",
34 waived: "Waived",
3435 overdue: "Overdue",
3536 soon: "Due soon",
3637 later: "Upcoming",
@@ -38,6 +39,7 @@ export const URGENCY_LABEL: Readonly<Record<Urgency, string>> = {
3839
3940 /** "Due Thu, Oct 15 · in 3 days", or "Done". */
4041 export function dueLine(d: DeadlineView, on: string): string {
42 if (d.waived_at !== null) return `Waived ${spoken(d.waived_at.slice(0, 10))}${d.waived_by === null ? "" : ` by ${d.waived_by}`} · was due ${spoken(d.due)}`;
4143 if (d.done_at !== null) return `Done · was due ${spoken(d.due)}`;
4244 return `Due ${spoken(d.due)} · ${relative(d.due, on)}`;
4345 }
@@ -57,7 +59,7 @@ export const rollForm = (d: DeadlineView, to: string): string =>
5759 </form>`;
5860
5961 export const badge = (d: DeadlineView, on: string): string => {
60 const u = urgency(d.due, on, d.done_at !== null);
62 const u = urgencyOf(d, on);
6163 return `<span class="badge" data-u="${u}">${URGENCY_LABEL[u]}</span>`;
6264 };
6365
@@ -157,9 +159,11 @@ export const draftLink = (draft: Draft, on: string): string =>
157159 export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: string, agent: Agent = defaults): string {
158160 const id = sheetId(d);
159161 const may = canChange(who, deal);
160 const drafts = d.done_at === null ? draftsFor(deal, d, agent) : [];
162 const drafts = isOpen(d) ? draftsFor(deal, d, agent) : [];
161163 const reminders =
162 d.done_at !== null
164 d.waived_at !== null
165 ? `<p class="muted">Waived, so no reminders go out.</p>`
166 : d.done_at !== null
163167 ? `<p class="muted">Done, so no reminders go out.</p>`
164168 : drafts.length === 0
165169 ? `<p class="muted">No one to remind yet — <a href="/deals/${deal.id}#parties">add the parties</a>.</p>`
@@ -180,9 +184,26 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to:
180184 .join("")}</ul></section>`;
181185 const actions = may
182186 ? `<section class="sheet-actions">
183 <form method="post" action="/deadlines/${d.id}/done">${hidden({ done: d.done_at === null ? 1 : 0, to })}
187 ${
188 d.waived_at !== null
189 ? `<form method="post" action="/deadlines/${d.id}/waive">${hidden({ waived: 0, to })}
190 <button class="button">Un-waive</button>
191 </form>`
192 : `<form method="post" action="/deadlines/${d.id}/done">${hidden({ done: d.done_at === null ? 1 : 0, to })}
184193 <button class="button${d.done_at === null ? "" : " button-quiet"}">${d.done_at === null ? "Mark done" : "Reopen"}</button>
185 </form>
194 </form>${
195 isOpen(d) && isWaivable(d.kind)
196 ? confirmRemove({
197 summary: "Waive…",
198 goes: `${d.label} is given up on purpose: it stays on the deal, marked Waived, and sends no more reminders.`,
199 action: `/deadlines/${d.id}/waive`,
200 fields: { to, waived: "1" },
201 name: `Yes, waive ${d.label}`,
202 yes: "Yes, waive",
203 })
204 : ""
205 }`
206 }
186207 <form class="move" method="post" action="/deadlines/${d.id}/move">${hidden({ to })}
187208 <label>New date<input class="input" type="date" name="due" value="${escape(d.due)}" required></label>
188209 <label>Why it moved<input class="input" name="reason" maxlength="200" required placeholder="e.g. Lender asked for 3 more days"></label>
@@ -220,7 +241,7 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to:
220241 ${conflictLines(deal, d)}
221242 ${nonBusinessLine(d)}${may ? rollForm(d, to) : ""}
222243 ${moves}
223 <section><h3>Reminders</h3>${d.done_at === null ? `<p class="muted">${remindsLine(d.lead_days)}</p>` : ""}${reminders}</section>
244 <section><h3>Reminders</h3>${isOpen(d) ? `<p class="muted">${remindsLine(d.lead_days)}</p>` : ""}${reminders}</section>
224245 ${actions}
225246 </div>`;
226247 }
src/people.test.ts +1 −1
@@ -9,7 +9,7 @@ const deal = (id: number, address: string, parties: [number, string, string, str
99 address,
1010 closed,
1111 parties: parties.map(([pid, role, name, contact]) => ({ id: pid, deal_id: id, role, name, contact })),
12 deadlines: dates.map(([did, owes, label, due, done_at]) => ({ id: did, owes, label, due, done_at })),
12 deadlines: dates.map(([did, owes, label, due, done_at]) => ({ id: did, owes, label, due, done_at, waived_at: null })),
1313 }) as unknown as DealView;
1414
1515 const deals = [
src/people.ts +2 −2
@@ -6,7 +6,7 @@
66
77 import { urgency, type Urgency } from "./dates.ts";
88 import type { DealView } from "./deals.ts";
9 import { PARTY_LABEL, type PartyRole } from "./deadlines.ts";
9 import { isOpen, PARTY_LABEL, type PartyRole } from "./deadlines.ts";
1010
1111 export interface Owed {
1212 readonly deal_id: number;
@@ -48,7 +48,7 @@ export function people(deals: readonly DealView[], on: string): Person[] {
4848 // A closed deal is off the clock: nothing on it is chased.
4949 if (deal.closed) continue;
5050 for (const d of deal.deadlines) {
51 if (d.owes !== party.role || d.done_at !== null) continue;
51 if (d.owes !== party.role || !isOpen(d)) continue;
5252 one.owes.set(d.id, {
5353 deal_id: deal.id,
5454 address: deal.address,
src/progress.ts +2 −1
@@ -5,6 +5,7 @@
55 */
66
77 import { daysBetween } from "./dates.ts";
8 import { isSettled } from "./deadlines.ts";
89 import type { DealView } from "./deals.ts";
910
1011 export interface Progress {
@@ -22,7 +23,7 @@ export function progress(
2223 let done = 0;
2324 let overdue = 0;
2425 for (const d of deal.deadlines) {
25 if (d.done_at !== null) done++;
26 if (isSettled(d)) done++;
2627 else if (d.due < on) overdue++;
2728 }
2829 return {
src/reminders.ts +8 −7
@@ -10,7 +10,7 @@
1010
1111 import { addDays, relative, spoken, today } from "./dates.ts";
1212 import { memoizer, print } from "./memo.ts";
13 import { DEFAULT_LEAD, KIND, PARTY_LABEL, type PartyRole } from "./deadlines.ts";
13 import { DEFAULT_LEAD, isOpen, KIND, PARTY_LABEL, type PartyRole } from "./deadlines.ts";
1414 import type { DealView, DeadlineView, Move, Moment, Party } from "./deals.ts";
1515
1616 export interface Agent {
@@ -114,7 +114,7 @@ function noticeFor(deal: DealView, deadline: DeadlineView, party: Party): Notice
114114 if (last.amendment === 0) return { items: [{ deadline, move: last }], key: last.id };
115115 const told = (d: DeadlineView): boolean => recipients(deal, d, "moved").some((p) => p.id === party.id);
116116 const items = deal.deadlines
117 .filter((d) => d.done_at === null && told(d))
117 .filter((d) => isOpen(d) && told(d))
118118 .flatMap((d) => {
119119 const move = lastMove(d);
120120 return move !== undefined && move.amendment === last.amendment ? [{ deadline: d, move }] : [];
@@ -175,7 +175,7 @@ export function drafts(deal: DealView, agent: Agent): readonly Draft[] {
175175 if (deal.closed) return [];
176176 return remembered(`${JSON.stringify(agent)}|${print(deal)}`, () =>
177177 deal.deadlines
178 .filter((d) => d.done_at === null)
178 .filter(isOpen)
179179 .flatMap((deadline) => draftsFor(deal, deadline, agent)),
180180 );
181181 }
@@ -235,7 +235,7 @@ const NEXT_MAX = 4;
235235 export function standing(deal: DealView): number {
236236 let h = 2166136261;
237237 const text = deal.deadlines
238 .map((d) => `${d.id}:${d.due}:${d.done_at === null ? 0 : 1}`)
238 .map((d) => `${d.id}:${d.due}:${d.waived_at !== null ? 2 : d.done_at === null ? 0 : 1}`)
239239 .sort()
240240 .join("|");
241241 for (let i = 0; i < text.length; i++) h = Math.imul(h ^ text.charCodeAt(i), 16777619) >>> 0;
@@ -253,12 +253,12 @@ export const standingOf = (moveId: number): number => moveId % SEND_SPAN;
253253 /** The words of a status update to one party. */
254254 function statusWords(deal: DealView, party: Party, agent: Agent): { subject: string; body: string } {
255255 const closing = deal.deadlines.find((d) => d.kind === "closing")!;
256 const done = deal.deadlines.filter((d) => d.done_at !== null);
257 const open = deal.deadlines.filter((d) => d.done_at === null && d.id !== closing.id).sort((a, b) => a.due.localeCompare(b.due));
256 const done = deal.deadlines.filter((d) => !isOpen(d));
257 const open = deal.deadlines.filter((d) => isOpen(d) && d.id !== closing.id).sort((a, b) => a.due.localeCompare(b.due));
258258 const owner = (d: DeadlineView): string => deal.parties.find((p) => p.role === d.owes)?.name ?? PARTY_LABEL[d.owes];
259259 const next = open.slice(0, NEXT_MAX).map((d) => `• ${d.label}: ${spoken(d.due)} (${owner(d)} · ${PARTY_LABEL[d.owes].toLowerCase()})`);
260260 const more = open.length > NEXT_MAX ? `\n• …and ${open.length - NEXT_MAX} more after that` : "";
261 const finished = done.length === 0 ? "Nothing is finished yet." : done.map((d) => `• ${d.label}`).join("\n");
261 const finished = done.length === 0 ? "Nothing is finished yet." : done.map((d) => `• ${d.label}${d.waived_at === null ? "" : " (waived)"}`).join("\n");
262262 return {
263263 subject: `${deal.address} — where things stand`,
264264 body: `Hi ${first(party.name)}, here is where things stand on ${deal.address}.\n\nDone:\n${finished}\n\nNext:\n${next.length === 0 ? "Nothing else before closing." : next.join("\n")}${more}\n\nClosing is ${spoken(closing.due)} (${relative(closing.due, today())}).\n\nLet me know if you have any questions.\n\n${signOff(agent)}`,
@@ -308,6 +308,7 @@ export function statusDrafts(deal: DealView, agent: Agent): Draft[] {
308308
309309 /** The draft of `moment` that `party` has on `deadline`, if any: a reminder, or the deal's status update on its closing date. */
310310 export function draftOfMoment(deal: DealView, deadline: DeadlineView, agent: Agent, party: Party, moment: Moment): Draft | undefined {
311 if (moment !== "status" && !isOpen(deadline)) return undefined;
311312 const these = moment === "status" ? (deadline.kind === "closing" ? statusDrafts(deal, agent) : []) : draftsFor(deal, deadline, agent);
312313 return these.find((r) => r.party_id === party.id && r.moment === moment);
313314 }
src/routes.ts +35
@@ -50,6 +50,7 @@ import {
5050 withConflicts,
5151 listDeals,
5252 markDone,
53 waiveDate,
5354 mayOpen,
5455 openDealAt,
5556 plan,
@@ -210,6 +211,8 @@ export const DEAL: Schema = {
210211 owes: ROLE,
211212 what: { type: "string" },
212213 done_at: { type: ["string", "null"] },
214 waived_at: { type: ["string", "null"], description: "When the buyer waived this date on purpose; null while it stands. A waived date is settled: no reminders, flags or conflicts." },
215 waived_by: { type: ["string", "null"], description: "Who recorded the waiver." },
213216 moves: { type: "array", items: { type: "object" } },
214217 nonBusinessDay: {
215218 type: ["object", "null"],
@@ -861,6 +864,19 @@ export const routes: readonly Route[] = [
861864 return done(markDone(c.db, c.who, { id: Number(c.params.id), done: isDone }), backTo(f.to), isDone ? "Marked done." : "Reopened.");
862865 },
863866 },
867 {
868 method: "POST",
869 path: "/deadlines/:id/waive",
870 handle: async (c) => {
871 const f = await form(c);
872 if (f instanceof Response) return f;
873 const waived = f.waived !== "0";
874 if (waived && f.confirm !== "yes") return unconfirmed(c, backTo(f.to));
875 const label = nameOf(c.db, "deadline", Number(c.params.id));
876 const result = waiveDate(c.db, c.who, { id: Number(c.params.id), waived });
877 return done(result, backTo(f.to), label === undefined ? undefined : waived ? `Waived ${label}.` : `${label} is open again.`);
878 },
879 },
864880 {
865881 method: "POST",
866882 path: "/deadlines/:id/move",
@@ -1226,6 +1242,25 @@ export const routes: readonly Route[] = [
12261242 answer: { type: "object", properties: { id: { type: "integer" }, lead_days: { type: "integer" } }, required: ["id", "lead_days"] },
12271243 },
12281244 },
1245 {
1246 method: "POST",
1247 path: "/api/deals/:id/deadlines/:deadline/waive",
1248 handle: (c) => answer(waiveDate(c.db, c.who, { id: Number(c.params.deadline), dealId: Number(c.params.id), waived: true })),
1249 api: {
1250 summary:
1251 "Waive a date the buyer gave up on purpose: it stays on the deal, settled (counted in progress), and drafts no more reminders, follow-up, business-day flag or after-closing conflict; its waiting reminders leave the review. The day and who waived it are kept. Closing is refused (422), as is a date already done or waived.",
1252 answer: { type: "object", properties: { id: { type: "integer" }, waived_at: { type: ["string", "null"] }, waived_by: { type: ["string", "null"] } }, required: ["id", "waived_at", "waived_by"] },
1253 },
1254 },
1255 {
1256 method: "DELETE",
1257 path: "/api/deals/:id/deadlines/:deadline/waive",
1258 handle: (c) => answer(waiveDate(c.db, c.who, { id: Number(c.params.deadline), dealId: Number(c.params.id), waived: false })),
1259 api: {
1260 summary: "Un-waive a date: it comes back open with its date unchanged, and its reminders are drafted again. Refused (422) when it is not waived.",
1261 answer: { type: "object", properties: { id: { type: "integer" }, waived_at: { type: ["string", "null"] }, waived_by: { type: ["string", "null"] } }, required: ["id", "waived_at", "waived_by"] },
1262 },
1263 },
12291264 {
12301265 method: "DELETE",
12311266 path: "/api/deals/:id/deadlines/:deadline",
src/sample.test.ts +5 −4
@@ -11,8 +11,8 @@ import { isUntouched, shiftSample, type SampleDates } from "./sample.ts";
1111 const dates: SampleDates = {
1212 contractDate: "2026-09-01",
1313 deadlines: [
14 { id: 1, due: "2026-09-11", doneAt: "2026-09-30T17:00:00.000Z" },
15 { id: 2, due: "2026-10-05", doneAt: null },
14 { id: 1, due: "2026-09-11", doneAt: "2026-09-30T17:00:00.000Z", waivedAt: null },
15 { id: 2, due: "2026-10-05", doneAt: null, waivedAt: null },
1616 ],
1717 moves: [{ id: 7, fromDue: "2026-09-22", toDue: "2026-10-03" }],
1818 };
@@ -21,8 +21,8 @@ test("every date of a sample moves by the days since its anchor, together", () =
2121 const a = shiftSample(dates, "2026-10-01", "2026-10-31");
2222 expect(a.contractDate).toBe("2026-10-01");
2323 expect(a.deadlines).toEqual([
24 { id: 1, due: "2026-10-11", doneAt: "2026-10-30T17:00:00.000Z" },
25 { id: 2, due: "2026-11-04", doneAt: null },
24 { id: 1, due: "2026-10-11", doneAt: "2026-10-30T17:00:00.000Z", waivedAt: null },
25 { id: 2, due: "2026-11-04", doneAt: null, waivedAt: null },
2626 ]);
2727 expect(a.moves).toEqual([{ id: 7, fromDue: "2026-10-22", toDue: "2026-11-02" }]);
2828 // A month later again: the same gap between dates, a different shift.
@@ -39,6 +39,7 @@ test("a sample a person changed is not untouched", () => {
3939 customs: 1,
4040 reminders: 0,
4141 doneAts: ["2026-09-30T17:00:00.000Z", "2026-09-30T17:00:00.000Z", "2026-09-30T17:00:00.000Z", null],
42 waivedAts: [null, null, null, null],
4243 moveAuthors: ["Sample data"],
4344 };
4445 expect(isUntouched(state, "2026-10-01")).toBe(true);
src/sample.ts +15 −5
@@ -23,6 +23,8 @@ interface Sample {
2323 readonly lengths?: Partial<typeof BRIEF_LENGTHS>;
2424 readonly parties: readonly [PartyRole, string, string][];
2525 readonly done?: readonly string[];
26 /** Kinds the buyer waived on purpose. */
27 readonly waived?: readonly string[];
2628 readonly custom?: readonly [string, number, PartyRole, string][];
2729 readonly moved?: readonly [string, number, string];
2830 /** A reminder already sent, in the agent's own edited words: date kind, party role, moment, subject, body. */
@@ -91,6 +93,7 @@ const SAMPLES: readonly Sample[] = [
9193 ["lender", "Owen Brandt, First Keel Bank", "[email protected]"],
9294 ["other_agent", "Jordan Ellis, Crestline Homes", "(555) 014-2290"],
9395 ],
96 waived: ["appraisal"],
9497 },
9598 ];
9699
@@ -100,7 +103,7 @@ const DONE_TIME = "T17:00:00.000Z";
100103 /** The dates of one sample deal, as plain data. */
101104 export interface SampleDates {
102105 readonly contractDate: string;
103 readonly deadlines: readonly { readonly id: number; readonly due: string; readonly doneAt: string | null }[];
106 readonly deadlines: readonly { readonly id: number; readonly due: string; readonly doneAt: string | null; readonly waivedAt: string | null }[];
104107 readonly moves: readonly { readonly id: number; readonly fromDue: string; readonly toDue: string }[];
105108 }
106109
@@ -119,6 +122,7 @@ export function shiftSample(dates: SampleDates, anchor: string, on: string): Sam
119122 id: d.id,
120123 due: addDays(d.due, days),
121124 doneAt: d.doneAt === null ? null : addDays(d.doneAt.slice(0, 10), days) + d.doneAt.slice(10),
125 waivedAt: d.waivedAt === null ? null : addDays(d.waivedAt.slice(0, 10), days) + d.waivedAt.slice(10),
122126 })),
123127 moves: dates.moves.map((m) => ({ id: m.id, fromDue: addDays(m.fromDue, days), toDue: addDays(m.toDue, days) })),
124128 };
@@ -132,6 +136,7 @@ export interface SampleState {
132136 readonly customs: number;
133137 readonly reminders: number;
134138 readonly doneAts: readonly (string | null)[];
139 readonly waivedAts: readonly (string | null)[];
135140 readonly moveAuthors: readonly string[];
136141 }
137142
@@ -146,6 +151,8 @@ export function isUntouched(state: SampleState, anchor: string): boolean {
146151 state.reminders === 0 &&
147152 state.doneAts.every((d) => d === null || d === marker) &&
148153 state.doneAts.filter((d) => d !== null).length === (s.done?.length ?? 0) &&
154 state.waivedAts.every((d) => d === null || d === marker) &&
155 state.waivedAts.filter((d) => d !== null).length === (s.waived?.length ?? 0) &&
149156 state.moveAuthors.length === (s.moved === undefined ? 0 : 1) &&
150157 state.moveAuthors.every((a) => a === SAMPLE.name)
151158 );
@@ -166,8 +173,8 @@ export function refresh(db: Database, on = today()): void {
166173 "SELECT d.id, s.sample, d.contract_date FROM deal d LEFT JOIN sample_deal s ON s.deal_id = d.id WHERE d.author_id = ?1",
167174 ).all(SAMPLE.id);
168175 for (const deal of deals) {
169 const deadlines = db.query<{ id: number; kind: string; due: string; done_at: string | null }, [number]>(
170 "SELECT id, kind, due, done_at FROM deadline WHERE deal_id = ?1",
176 const deadlines = db.query<{ id: number; kind: string; due: string; done_at: string | null; waived_at: string | null }, [number]>(
177 "SELECT id, kind, due, done_at, waived_at FROM deadline WHERE deal_id = ?1",
171178 ).all(deal.id);
172179 const moves = db.query<{ id: number; from_due: string; to_due: string; by_name: string }, [number]>(
173180 "SELECT m.id, m.from_due, m.to_due, m.by_name FROM deadline_move m JOIN deadline d ON d.id = m.deadline_id WHERE d.deal_id = ?1",
@@ -184,20 +191,21 @@ export function refresh(db: Database, on = today()): void {
184191 customs: deadlines.filter((d) => d.kind === "custom").length,
185192 reminders,
186193 doneAts: deadlines.map((d) => d.done_at),
194 waivedAts: deadlines.map((d) => d.waived_at),
187195 moveAuthors: moves.map((m) => m.by_name),
188196 };
189197 if (!isUntouched(state, anchor)) continue;
190198 const shifted = shiftSample(
191199 {
192200 contractDate: deal.contract_date,
193 deadlines: deadlines.map((d) => ({ id: d.id, due: d.due, doneAt: d.done_at })),
201 deadlines: deadlines.map((d) => ({ id: d.id, due: d.due, doneAt: d.done_at, waivedAt: d.waived_at })),
194202 moves: moves.map((m) => ({ id: m.id, fromDue: m.from_due, toDue: m.to_due })),
195203 },
196204 anchor,
197205 on,
198206 );
199207 db.query("UPDATE deal SET contract_date = ?1 WHERE id = ?2").run(shifted.contractDate, deal.id);
200 for (const d of shifted.deadlines) db.query("UPDATE deadline SET due = ?1, done_at = ?2 WHERE id = ?3").run(d.due, d.doneAt, d.id);
208 for (const d of shifted.deadlines) db.query("UPDATE deadline SET due = ?1, done_at = ?2, waived_at = ?3 WHERE id = ?4").run(d.due, d.doneAt, d.waivedAt, d.id);
201209 for (const m of shifted.moves) db.query("UPDATE deadline_move SET from_due = ?1, to_due = ?2 WHERE id = ?3").run(m.fromDue, m.toDue, m.id);
202210 // The sample's sent reminder follows its date, so it stays "yesterday's".
203211 const days = `+${daysBetween(anchor, on)} days`;
@@ -225,6 +233,8 @@ function writeSamples(db: Database, on: string): void {
225233 db.query("INSERT INTO party (deal_id, role, name, contact) VALUES (?1, ?2, ?3, ?4)").run(deal.id, role, name, contact);
226234 for (const kind of s.done ?? [])
227235 db.query("UPDATE deadline SET done_at = ?1 WHERE deal_id = ?2 AND kind = ?3").run(`${addDays(on, -1)}T17:00:00.000Z`, deal.id, kind);
236 for (const kind of s.waived ?? [])
237 db.query("UPDATE deadline SET waived_at = ?1, waived_by = ?2 WHERE deal_id = ?3 AND kind = ?4").run(`${addDays(on, -1)}${DONE_TIME}`, SAMPLE.name, deal.id, kind);
228238 for (const [label, days, owes, what] of s.custom ?? [])
229239 db.query("INSERT INTO deadline (deal_id, kind, label, due, owes, what) VALUES (?1, 'custom', ?2, ?3, ?4, ?5)").run(deal.id, label, addDays(on, days), owes, what);
230240 if (s.sent !== undefined) {
src/security.ts +2 −2
@@ -98,8 +98,8 @@ export function doorOf(
9898 const verb = ROW_VERB[method];
9999 return verb === undefined ? undefined : { resource, verb };
100100 }
101 // `<api>/:id/<children>/:child` (or `/:action`, posted): a change inside the row is an update of it.
102 if (rest !== undefined && (/^[^/]+\/[^/]+\/[^/]+$/.test(rest) || (method === "POST" && /^[^/]+\/amend$/.test(rest))))
101 // `<api>/:id/<children>/:child` (or `…/:child/waive`, or `/:action`, posted): a change inside the row is an update of it.
102 if (rest !== undefined && (/^[^/]+\/[^/]+\/[^/]+(\/waive)?$/.test(rest) || (method === "POST" && /^[^/]+\/amend$/.test(rest))))
103103 return method === "PATCH" || method === "DELETE" || method === "POST" ? { resource, verb: "update" } : undefined;
104104 }
105105 return undefined;
src/server.test.ts +1
@@ -178,6 +178,7 @@ test("the MCP server lists the tools and calls them as the caller", async () =>
178178 "this_week",
179179 "list_people",
180180 "mark_done",
181 "waive_date",
181182 "move_date",
182183 "set_reminder_lead",
183184 "amend_deal",
src/terminal.ts +20 −13
@@ -12,7 +12,7 @@
1212 * profile your name, brokerage, phone and email (I); e edits them, U goes back to the defaults
1313 * deal one deal's dates and parties; a adds a date, p a party, A corrects the address, M amends the contract, S drafts a status update for the party under the cursor, D removes it
1414 *
15 * On a date (dates or deal view): x marks it done, u reopens it, m moves it
15 * On a date (dates or deal view): x marks it done, W waives it (the buyer gave it up), u reopens it or un-waives it, m moves it
1616 * (a new date, then the reason), N moves one flagged "not a business day" to the next business day, l sets how many days before it reminds. o or enter opens its deal; n opens a new
1717 * deal (address, buyer, seller, contract and closing dates); d, r and b move
1818 * between views; esc cancels a prompt; q leaves. / finds a deal by address or
@@ -21,7 +21,7 @@
2121
2222 import type { Database } from "bun:sqlite";
2323 import { timelineRows } from "./timeline.ts";
24 import { isDate, relative, spoken, today, urgency, type Urgency } from "./dates.ts";
24 import { isDate, relative, spoken, today, urgencyOf, type Urgency } from "./dates.ts";
2525 import {
2626 addDeadline,
2727 addParty,
@@ -35,6 +35,7 @@ import {
3535 closedOn,
3636 listDeals,
3737 markDone,
38 waiveDate,
3839 mayOpen,
3940 planFor,
4041 plannedDates,
@@ -58,7 +59,7 @@ import {
5859 import { find, FIND_MAX, query } from "./find.ts";
5960 import { mayRestore, restoreSamples } from "./actions.ts";
6061 import { conflictLine } from "./order.ts";
61 import { PARTY_LABEL, PARTY_ROLES, type PartyRole } from "./deadlines.ts";
62 import { isOpen, PARTY_LABEL, PARTY_ROLES, type PartyRole } from "./deadlines.ts";
6263 import { agentOf, getProfile, setProfile, useDefaults } from "./profile.ts";
6364 import { permit } from "./contract.ts";
6465 import { drafts, momentLabel, pending, remindsLine, sentLabel, unsent, type Agent, type Draft } from "./reminders.ts";
@@ -75,7 +76,7 @@ const dim = (s: string): string => `${esc}2m${s}${esc}0m`;
7576 const bold = (s: string): string => `${esc}1m${s}${esc}0m`;
7677 /** Audit rows to a screen. */
7778 const ACTIVITY_ROWS = 20;
78 const COLOUR: Readonly<Record<Urgency, string>> = { overdue: "31", soon: "33", later: "36", done: "2" };
79 const COLOUR: Readonly<Record<Urgency, string>> = { overdue: "31", soon: "33", later: "36", done: "2", waived: "2" };
7980 const tint = (u: Urgency, s: string): string => `${esc}${COLOUR[u]}m${s}${esc}0m`;
8081
8182 type View = "dates" | "week" | "people" | "reminders" | "deal" | "messages" | "timeline" | "profile" | "activity";
@@ -141,7 +142,7 @@ export function terminal(
141142 if (view === "week") return thisWeek(deals(), on()).map(({ deal, deadline }) => ({ deal, date: deadline }));
142143 return deals()
143144 .flatMap((deal) =>
144 (deal.closed && !showDone ? [] : deal.deadlines.filter((d) => showDone || d.done_at === null)).map((date) => ({ deal, date })),
145 (deal.closed && !showDone ? [] : deal.deadlines.filter((d) => showDone || isOpen(d))).map((date) => ({ deal, date })),
145146 )
146147 .sort((a, b) => a.date.due.localeCompare(b.date.due) || a.date.id - b.date.id);
147148 };
@@ -180,14 +181,20 @@ export function terminal(
180181
181182 function onDate(key: string): boolean {
182183 const row = dateRows()[cursor];
183 if (!["x", "u", "m", "N", "l", "o", "\r"].includes(key)) return false;
184 if (!["x", "u", "W", "m", "N", "l", "o", "\r"].includes(key)) return false;
184185 if (row === undefined) {
185186 said = "No date here.";
186187 return true;
187188 }
188189 const { deal, date } = row;
189190 if (key === "x") said = report(markDone(db, me, { id: date.id, done: true }), `Done: ${date.label}, ${deal.address}.`);
190 if (key === "u") said = report(markDone(db, me, { id: date.id, done: false }), `Reopened: ${date.label}, ${deal.address}.`);
191 if (key === "u")
192 said =
193 date.waived_at === null
194 ? report(markDone(db, me, { id: date.id, done: false }), `Reopened: ${date.label}, ${deal.address}.`)
195 : report(waiveDate(db, me, { id: date.id, waived: false }), `Un-waived: ${date.label}, ${deal.address}.`);
196 if (key === "W")
197 said = report(waiveDate(db, me, { id: date.id, waived: true }), `Waived: ${date.label}, ${deal.address}.`);
191198 if (key === "m")
192199 ask(deal, [`New date for ${date.label} (YYYY-MM-DD, now ${date.due})`, "Why it moved"], ([due, reason]) =>
193200 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.`)),
@@ -243,7 +250,7 @@ export function terminal(
243250 report(updateDeal(db, me, { id: deal.id, address }), `Address is now ${address!.trim()}.`),
244251 );
245252 if (key === "M") {
246 const open = deal.deadlines.filter((d) => d.done_at === null);
253 const open = deal.deadlines.filter(isOpen);
247254 ask(deal, [...open.map((d) => `${d.label} (now ${d.due}; blank keeps it)`), "Why the dates moved"], (answers) => {
248255 const dates = Object.fromEntries(open.flatMap((d, i) => (answers[i]!.trim() === "" ? [] : [[String(d.id), answers[i]!.trim()]])));
249256 const count = Object.keys(dates).length;
@@ -589,14 +596,14 @@ export function terminal(
589596
590597 const dateLine = (row: Row, i: number, withDeal: boolean): string => {
591598 const { date, deal } = row;
592 const u = urgency(date.due, on(), date.done_at !== null);
593 const when = tint(u, `${spoken(date.due).padEnd(12)} ${(date.done_at === null ? relative(date.due, on()) : "done").padEnd(12)}`);
599 const u = urgencyOf(date, on());
600 const when = tint(u, `${spoken(date.due).padEnd(12)} ${(isOpen(date) ? relative(date.due, on()) : date.waived_at !== null ? "waived" : "done").padEnd(12)}`);
594601 const who = owner(deal, date);
595602 const label = view === "week" ? `${date.label} — ${deal.address} · ${who.name ?? who.role}` : withDeal ? `${date.label} — ${deal.address}` : date.label;
596603 const text = label + (deal.closed && withDeal ? dim(" (closed)") : "");
597604 const moved = date.moves.length > 0 ? dim(` moved: ${date.moves.at(-1)!.reason}`) : "";
598605 const flag = date.nonBusinessDay === null ? "" : dim(` not a business day · next is ${spoken(date.nonBusinessDay.next)} (N moves it)`);
599 const lead = date.done_at === null ? dim(` reminds ${date.lead_days}d before`) : "";
606 const lead = isOpen(date) ? dim(` reminds ${date.lead_days}d before`) : "";
600607 return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${flag}${lead}${moved}`;
601608 };
602609
@@ -753,8 +760,8 @@ export function terminal(
753760 : view === "timeline"
754761 ? "b back to the deal · d dates · q quit"
755762 : view === "deal"
756 ? "j/k move · t client timeline · s messages · x done · u reopen · m move · N next business day · l remind lead · a add date · p add party · e edit party · A edit address · M amend the contract · S status update to the party · X remove date/party · D remove deal · b back · q quit"
757 : `j/k move · x done · u reopen · m move · N next business day · l lead · o open deal · n new deal · c check dates · / find · R restore samples · h ${showDone ? "hide" : "show"} done · w this week · r reminders · P people · I profile · L activity · q quit`;
763 ? "j/k move · t client timeline · s messages · x done · W waive · u reopen/un-waive · m move · N next business day · l remind lead · a add date · p add party · e edit party · A edit address · M amend the contract · S status update to the party · X remove date/party · D remove deal · b back · q quit"
764 : `j/k move · x done · W waive · u reopen · m move · N next business day · l lead · o open deal · n new deal · c check dates · / find · R restore samples · h ${showDone ? "hide" : "show"} done · w this week · r reminders · P people · I profile · L activity · q quit`;
758765 lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys));
759766 }
760767 return lines;
src/timeline.ts +4 −3
@@ -5,15 +5,16 @@
55 * internal — no notes, drafts, reasons or contacts.
66 */
77
8 import { spoken, urgency, type Urgency } from "./dates.ts";
8 import { spoken, urgencyOf, type Urgency } from "./dates.ts";
99 import type { DealView } from "./deals.ts";
1010 import { owner } from "./week.ts";
1111
12 export type TimelineStatus = "Done" | "Upcoming" | "Overdue";
12 export type TimelineStatus = "Done" | "Waived" | "Upcoming" | "Overdue";
1313
1414 /** Words first, so black and white reads the same as colour; the mark is only a helper. */
1515 const STATUS: Readonly<Record<Urgency, { mark: string; word: TimelineStatus }>> = {
1616 done: { mark: "✓", word: "Done" },
17 waived: { mark: "–", word: "Waived" },
1718 overdue: { mark: "!", word: "Overdue" },
1819 soon: { mark: "○", word: "Upcoming" },
1920 later: { mark: "○", word: "Upcoming" },
@@ -35,7 +36,7 @@ export interface TimelineRow {
3536
3637 export function timelineRows(deal: DealView, on: string): TimelineRow[] {
3738 return deal.deadlines.map((d) => {
38 const u = urgency(d.due, on, d.done_at !== null);
39 const u = urgencyOf(d, on);
3940 const { name, role } = owner(deal, d);
4041 return { label: d.label, due: d.due, spoken: spoken(d.due), role, name, status: STATUS[u].word, mark: STATUS[u].mark, urgency: u };
4142 });
src/waive.test.ts added +201
@@ -0,0 +1,201 @@
1 /** A waived date stays on its deal, settled: no reminders, flags or conflicts, and every door agrees. */
2 import { afterAll, beforeEach, 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 { addDays, today } from "./dates.ts";
7 import { openDb } from "./db.ts";
8 import { createDeal, getDeal, markDone, moveDeadline, waiveDate, type DealView } from "./deals.ts";
9 import { agent } from "./env.ts";
10 import { progress } from "./progress.ts";
11 import { drafts, standing, waitingCount } from "./reminders.ts";
12 import { sheet } from "./pages/sheet.ts";
13 import { timelineRows } from "./timeline.ts";
14 import { forgetRationing } from "./security.ts";
15 import { serve } from "./server.ts";
16 import { sign } from "./who.ts";
17 import { terminal } from "./terminal.ts";
18 import type { Who } from "./who.ts";
19
20 const db = openDb(mkdtempSync(join(tmpdir(), "app-waive-")));
21 const alice: Who = { role: "user", id: "u1", name: "alice" };
22 const anon: Who = { role: "anon" };
23 const made = createDeal(db, alice, {
24 openAnyway: true,
25 address: "3 Waiver Way",
26 buyer: "Ann Buyer",
27 seller: "Sam Seller",
28 contractDate: addDays(today(), -10),
29 closingDate: addDays(today(), 30),
30 });
31 if (!made.ok) throw new Error(made.message);
32 const deal = (): DealView => {
33 const got = getDeal(db, alice, { id: made.value.id });
34 if (!got.ok) throw new Error(got.message);
35 return got.value;
36 };
37 const date = (kind: string) => deal().deadlines.find((d) => d.kind === kind)!;
38 // The buyer can be reached, so an open date drafts reminders for them.
39 db.query("UPDATE party SET contact = '[email protected]' WHERE deal_id = ?1 AND role = 'buyer'").run(made.value.id);
40 const remindersOn = (kind: string) => drafts(deal(), agent).filter((r) => r.deadline_id === date(kind).id);
41
42 test("waiving records the day and who, and stops the reminders; un-waiving brings them back with the date unchanged", () => {
43 const due = date("financing").due;
44 expect(remindersOn("financing").length).toBeGreaterThan(0);
45 const waived = waiveDate(db, alice, { id: date("financing").id, waived: true });
46 expect(waived.ok).toBe(true);
47 expect(date("financing")).toMatchObject({ waived_by: "alice", done_at: null });
48 expect(date("financing").waived_at).toStartWith(today());
49 expect(remindersOn("financing")).toEqual([]);
50 expect(date("financing").nonBusinessDay).toBeNull();
51 expect(waiveDate(db, alice, { id: date("financing").id, waived: true }).ok).toBe(false);
52 expect(waiveDate(db, alice, { id: date("financing").id, waived: false }).ok).toBe(true);
53 expect(date("financing")).toMatchObject({ waived_at: null, waived_by: null, due });
54 expect(remindersOn("financing").length).toBeGreaterThan(0);
55 expect(waiveDate(db, alice, { id: date("financing").id, waived: false }).ok).toBe(false);
56 });
57
58 test("waiving leaves the review and the header count, and an overdue follow-up", () => {
59 moveDeadline(db, alice, { id: date("inspection").id, due: addDays(today(), -3), reason: "Slipped" });
60 expect(remindersOn("inspection").some((r) => r.moment === "late")).toBe(true);
61 const before = waitingCount([deal()], today(), agent);
62 expect(before).toBeGreaterThan(0);
63 waiveDate(db, alice, { id: date("inspection").id, waived: true });
64 expect(remindersOn("inspection")).toEqual([]);
65 expect(waitingCount([deal()], today(), agent)).toBeLessThan(before);
66 waiveDate(db, alice, { id: date("inspection").id, waived: false });
67 moveDeadline(db, alice, { id: date("inspection").id, due: addDays(today(), 5), reason: "Back" });
68 });
69
70 test("progress counts a waived date as settled, and the timeline says Waived", () => {
71 const before = progress(deal(), today());
72 waiveDate(db, alice, { id: date("inspection").id, waived: true });
73 const after = progress(deal(), today());
74 expect(after.done).toBe(before.done + 1);
75 expect(after.total).toBe(before.total);
76 const row = timelineRows(deal(), today()).find((r) => r.label === date("inspection").label)!;
77 expect(row).toMatchObject({ status: "Waived", urgency: "waived" });
78 expect(row.mark).not.toBe("✓");
79 waiveDate(db, alice, { id: date("inspection").id, waived: false });
80 });
81
82 test("a waived date past closing is no conflict, and it changes the status update's standing", () => {
83 moveDeadline(db, alice, { id: date("financing").id, due: addDays(today(), 40), reason: "Lender" });
84 expect(deal().conflicts.length).toBe(1);
85 const before = standing(deal());
86 waiveDate(db, alice, { id: date("financing").id, waived: true });
87 expect(deal().conflicts).toEqual([]);
88 expect(standing(deal())).not.toBe(before);
89 });
90
91 test("Closing and a done date are not waivable, and a waived date is not marked done", () => {
92 expect(waiveDate(db, alice, { id: date("closing").id, waived: true })).toMatchObject({ ok: false, error: "invalid" });
93 markDone(db, alice, { id: date("title").id, done: true });
94 expect(waiveDate(db, alice, { id: date("title").id, waived: true }).ok).toBe(false);
95 markDone(db, alice, { id: date("title").id, done: false });
96 expect(markDone(db, alice, { id: date("financing").id, done: true }).ok).toBe(false);
97 });
98
99 test("someone who may not update the deal is refused, and the refusal is audited", () => {
100 const refused = waiveDate(db, anon, { id: date("walkthrough").id, waived: true });
101 expect(refused).toMatchObject({ ok: false });
102 expect(date("walkthrough").waived_at).toBeNull();
103 const row = db.query<{ outcome: string }, []>("SELECT outcome FROM audit WHERE what = 'date.waive' ORDER BY id DESC LIMIT 1").get();
104 expect(row?.outcome).not.toBe("allowed");
105 const done = markDone(db, anon, { id: date("walkthrough").id, done: true });
106 expect(done).toMatchObject({ ok: false, error: (refused as { error: string }).error });
107 });
108
109 test("the sheet offers Waive beside Mark done, but never on Closing, and Un-waive on a waived date", () => {
110 const html = (kind: string) => sheet(deal(), date(kind), alice, today(), "/");
111 expect(html("inspection")).toContain("Mark done");
112 expect(html("inspection")).toContain(`action="/deadlines/${date("inspection").id}/waive"`);
113 expect(html("inspection")).toContain("Yes, waive");
114 expect(html("closing")).not.toContain("/waive");
115 waiveDate(db, alice, { id: date("walkthrough").id, waived: true });
116 expect(html("walkthrough")).toContain("Un-waive");
117 expect(html("walkthrough")).toContain("Waived, so no reminders go out.");
118 expect(html("walkthrough")).not.toContain("Mark done");
119 waiveDate(db, alice, { id: date("walkthrough").id, waived: false });
120 });
121
122 test("W in the terminal waives the date under the cursor, and u un-waives it", () => {
123 const t = terminal(db, alice, { title: "deal-clock", where: "test", agent });
124 const plain = (s: string) => s.replace(/\x1b\[[0-9;]*m/g, "");
125 const under = () => t.screen().map(plain).find((l) => l.startsWith("▸")) ?? "";
126 for (const c of ["/", "Waiver", "\r"]) t.press(c);
127 for (let i = 0; i < 20 && !under().includes("Final walkthrough"); i++) t.press("j");
128 expect(under()).toContain("3 Waiver Way");
129 t.press("W");
130 expect(date("walkthrough").waived_at).not.toBeNull();
131 t.press("h");
132 for (let i = 0; i < 20 && !under().includes("Final walkthrough"); i++) t.press("j");
133 expect(under()).toContain("waived");
134 t.press("u");
135 expect(date("walkthrough").waived_at).toBeNull();
136 });
137
138 const KEY = "a-key-only-the-forge-holds";
139 const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-waive-http-")), identityKey: KEY });
140 const base = `http://${server.hostname}:${server.port}`;
141 afterAll(() => server.stop(true));
142 beforeEach(forgetRationing);
143 const identity = `u9|nora|user|${Date.now() + 600_000}`;
144 const me = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) };
145 const json = { ...me, "content-type": "application/json" };
146
147 test("the page, the API, MCP and Activity agree", async () => {
148 const created = await fetch(base + "/api/deals", {
149 method: "POST",
150 headers: json,
151 body: JSON.stringify({ address: "8 Door Dr", open_anyway: true, buyer: "A", seller: "B", contract_date: "2026-10-01", closing_date: "2026-12-01" }),
152 });
153 const d = (await created.json()) as DealView;
154 const [inspection, appraisal, financing] = ["inspection", "appraisal", "financing"].map((k) => d.deadlines.find((x) => x.kind === k)!);
155 const url = (x: { id: number }) => `${base}/api/deals/${d.id}/deadlines/${x.id}/waive`;
156
157 // API: waive, refuse twice, undo.
158 const w = await fetch(url(inspection!), { method: "POST", headers: me });
159 expect(w.status).toBe(200);
160 expect(await w.json()).toMatchObject({ id: inspection!.id, waived_by: "nora" });
161 expect((await fetch(url(inspection!), { method: "POST", headers: me })).status).toBe(422);
162 const closing = d.deadlines.find((x) => x.kind === "closing")!;
163 expect((await fetch(url(closing), { method: "POST", headers: me })).status).toBe(422);
164 const shown = (await (await fetch(`${base}/api/deals/${d.id}`, { headers: me })).json()) as DealView & { progress: { done: number } };
165 expect(shown.deadlines.find((x) => x.id === inspection!.id)!.waived_at).not.toBeNull();
166 expect(shown.progress.done).toBe(1);
167
168 // The page's sheet shows the same.
169 const page = await (await fetch(`${base}/deals/${d.id}`, { headers: me })).text();
170 expect(page).toContain("Un-waive");
171 expect(page).toContain('data-u="waived"');
172 const timeline = await (await fetch(`${base}/deals/${d.id}/timeline`, { headers: me })).text();
173 expect(timeline).toContain("Waived");
174
175 // A stranger and another user are refused at the door.
176 expect((await fetch(url(appraisal!), { method: "POST", headers: { origin: base } })).status).toBeGreaterThanOrEqual(401);
177
178 expect((await fetch(url(inspection!), { method: "DELETE", headers: me })).status).toBe(200);
179 expect((await fetch(url(inspection!), { method: "DELETE", headers: me })).status).toBe(422);
180
181 // MCP.
182 const rpc = await fetch(base + "/mcp", {
183 method: "POST",
184 headers: json,
185 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "waive_date", arguments: { id: financing!.id } } }),
186 });
187 expect(JSON.stringify(await rpc.json())).toContain("waived_by");
188
189 // The page form asks once.
190 const form = (fields: Record<string, string>) =>
191 fetch(`${base}/deadlines/${appraisal!.id}/waive`, { method: "POST", body: new URLSearchParams(fields), headers: { ...me, "content-type": "application/x-www-form-urlencoded" }, redirect: "manual" });
192 expect((await form({ waived: "1", to: `/deals/${d.id}` })).status).toBe(422);
193 expect((await form({ waived: "1", confirm: "yes", to: `/deals/${d.id}` })).status).toBe(303);
194 const again = (await (await fetch(`${base}/api/deals/${d.id}`, { headers: me })).json()) as DealView;
195 expect(again.deadlines.find((x) => x.id === appraisal!.id)!.waived_at).not.toBeNull();
196
197 const root = `u1|root|admin|${Date.now() + 600_000}`;
198 const admin = { "x-forge-identity": root, "x-forge-signature": sign(root, KEY) };
199 const activity = await (await fetch(`${base}/activity`, { headers: admin })).text();
200 expect(activity).toContain("waived a date");
201 });
src/week.test.ts +1 −1
@@ -2,7 +2,7 @@ import { expect, test } from "bun:test";
22 import { thisWeek } from "./week.ts";
33
44 const on = "2026-11-02";
5 const d = (due: string, done: string | null = null) => ({ due, done_at: done });
5 const d = (due: string, done: string | null = null) => ({ due, done_at: done, waived_at: null });
66 const deals = [
77 { address: "B Street", deadlines: [d("2026-11-09"), d("2026-11-10"), d("2026-10-30")] },
88 { address: "A Street", deadlines: [d("2026-11-09"), d("2026-11-03", "2026-11-01"), d("2026-11-02")] },
src/week.ts +3 −3
@@ -4,7 +4,7 @@
44 */
55
66 import { addDays } from "./dates.ts";
7 import { PARTY_LABEL, type PartyRole } from "./deadlines.ts";
7 import { isOpen, PARTY_LABEL, type PartyRole } from "./deadlines.ts";
88
99 /** How many days past today still count as this week. */
1010 export const WEEK = 7;
@@ -21,7 +21,7 @@ export interface WeekItem<Deal, D> {
2121 readonly deadline: D;
2222 }
2323
24 export function thisWeek<D extends { due: string; done_at: string | null }, Deal extends WeekDeal<D>>(
24 export function thisWeek<D extends { due: string; done_at: string | null; waived_at: string | null }, Deal extends WeekDeal<D>>(
2525 deals: readonly Deal[],
2626 on: string,
2727 ): WeekItem<Deal, D>[] {
@@ -29,7 +29,7 @@ export function thisWeek<D extends { due: string; done_at: string | null }, Deal
2929 return deals
3030 .filter((deal) => deal.closed !== true)
3131 .flatMap((deal) =>
32 deal.deadlines.filter((d) => d.done_at === null && d.due <= last).map((deadline) => ({ deal, deadline })),
32 deal.deadlines.filter((d) => isOpen(d) && d.due <= last).map((deadline) => ({ deal, deadline })),
3333 )
3434 .sort(
3535 (a, b) =>
static/app.css +3
@@ -461,6 +461,8 @@ footer code {
461461 background: var(--color-overdue-bg);
462462 }
463463 .marker[data-u="done"],
464 .marker[data-u="waived"],
465 .badge[data-u="waived"],
464466 .badge[data-u="done"] {
465467 color: var(--color-muted);
466468 background: var(--color-done-bg);
@@ -484,6 +486,7 @@ footer code {
484486 .dot[data-u="overdue"] {
485487 background: var(--color-overdue);
486488 }
489 .dot[data-u="waived"],
487490 .dot[data-u="done"] {
488491 background: var(--color-done);
489492 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs