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
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/96-a-contingency-the-buyer-waives-is-marked → main 1 commit fork
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 | ||
| 105 | 105 | the appraiser gave. |
| 106 | 106 | 7. **Mark a date done.** On Alder Lane, open a coming date and tap Mark |
| 107 | 107 | 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. | |
| 108 | 112 | 8. **Add a party.** Tap the address 2210 Juniper Court to open the deal's |
| 109 | 113 | page. It lists every date and every party. Under "Add a party" pick a |
| 110 | 114 | role (the title company, say), type a name and an email or phone, and |
contract/openapi.json +172
| @@ -674,6 +674,20 @@ | ||
| 674 | 674 | "null" |
| 675 | 675 | ] |
| 676 | 676 | }, |
| 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 | }, | |
| 677 | 691 | "moves": { |
| 678 | 692 | "type": "array", |
| 679 | 693 | "items": { |
| @@ -1678,6 +1692,150 @@ | ||
| 1678 | 1692 | } |
| 1679 | 1693 | } |
| 1680 | 1694 | }, |
| 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 | }, | |
| 1681 | 1839 | "/api/audit": { |
| 1682 | 1840 | "get": { |
| 1683 | 1841 | "summary": "The audit trail, newest first; `before` pages back by id.", |
| @@ -1991,6 +2149,20 @@ | ||
| 1991 | 2149 | "null" |
| 1992 | 2150 | ] |
| 1993 | 2151 | }, |
| 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 | }, | |
| 1994 | 2166 | "moves": { |
| 1995 | 2167 | "type": "array", |
| 1996 | 2168 | "items": { |
docs/TECHNICAL.md +10 −2
| @@ -23,6 +23,14 @@ Removing a party or a date drops the reminders not yet sent; reminders already | ||
| 23 | 23 | marked sent stay on record. Over the API: `PATCH` or `DELETE |
| 24 | 24 | /api/deals/:id/parties/:party` and `DELETE /api/deals/:id/deadlines/:deadline`. |
| 25 | 25 | |
| 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 | ||
| 26 | 34 | Lead time: every date has `lead_days` (1 to 30, column `deadline.lead_days`, |
| 27 | 35 | default 3; new Financing dates and the sample deals start at 7, new Earnest money |
| 28 | 36 | 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 | ||
| 122 | 130 | `open_deal`, `add_date`, `update_address`, `add_party`, `edit_party`, `remove_party`, |
| 123 | 131 | `remove_date` — custom dates only — `remove_deal` — its author or an admin — |
| 124 | 132 | `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 | |
| 126 | 134 | four sample deals back and leaves every other deal alone). `send_reminder` takes an |
| 127 | 135 | optional `subject` and `body` to send edited words; without them the draft |
| 128 | 136 | goes as it is. |
| @@ -131,7 +139,7 @@ The terminal does the page's work too. It opens on every open date, soonest | ||
| 131 | 139 | first: `n` opens a new deal (address, buyer, seller, contract date, closing |
| 132 | 140 | date; the standard lengths do the rest; `c` asks the same five questions and |
| 133 | 141 | 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 | |
| 135 | 143 | its deal — where `a` adds a date, |
| 136 | 144 | `p` adds a party, `e` edits the party under the cursor (the cursor walks the |
| 137 | 145 | 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>> = { | ||
| 17 | 17 | "reminder.undo": "undid a declined reminder", |
| 18 | 18 | "date.move": "moved a date", |
| 19 | 19 | "date.done": "marked a date done", |
| 20 | "date.waive": "waived a date", | |
| 20 | 21 | "date.lead": "changed when a date's reminder goes out", |
| 21 | 22 | "date.add": "added a date", |
| 22 | 23 | "date.remove": "removed a date", |
src/dates.ts +5 −1
| @@ -150,7 +150,7 @@ export function relative(date: string, from: string): string { | ||
| 150 | 150 | return n > 0 ? `in ${n} days` : `${-n} days ago`; |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | export type Urgency = "done" | "overdue" | "soon" | "later"; | |
| 153 | export type Urgency = "done" | "waived" | "overdue" | "soon" | "later"; | |
| 154 | 154 | /** How a deadline looks on the clock: grey when done, red past due, amber within three days. */ |
| 155 | 155 | export function urgency(due: string, on: string, done: boolean): Urgency { |
| 156 | 156 | if (done) return "done"; |
| @@ -159,3 +159,7 @@ export function urgency(due: string, on: string, done: boolean): Urgency { | ||
| 159 | 159 | if (n <= 3) return "soon"; |
| 160 | 160 | return "later"; |
| 161 | 161 | } |
| 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[] = [ | ||
| 371 | 371 | DROP TABLE reminder_declined; |
| 372 | 372 | ALTER TABLE reminder_declined_new RENAME TO reminder_declined; |
| 373 | 373 | 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`, | |
| 374 | 377 | ]; |
| 375 | 378 | |
| 376 | 379 | export function openDb(dir = dataDir): Database { |
src/deadlines.ts +7
| @@ -23,6 +23,13 @@ export const PARTY_LABEL: Readonly<Record<PartyRole, string>> = { | ||
| 23 | 23 | title: "Title company", |
| 24 | 24 | other_agent: "Other agent", |
| 25 | 25 | }; |
| 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 | ||
| 26 | 33 | export const isPartyRole = (v: unknown): v is PartyRole => |
| 27 | 34 | PARTY_ROLES.includes(v as PartyRole); |
| 28 | 35 |
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 | ||
| 293 | 293 | const stamp = new Date("2026-10-12T08:00:00Z"); |
| 294 | 294 | const count = (ics: string) => ics.split("BEGIN:VEVENT").length - 1; |
| 295 | 295 | 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)); | |
| 297 | 297 | const before = book(deals, "clock.example", stamp); |
| 298 | 298 | expect(count(before)).toBe(openDates(deals).length); |
| 299 | 299 | 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"; | ||
| 12 | 12 | import { |
| 13 | 13 | DEFAULT_LENGTHS, |
| 14 | 14 | isClosed, |
| 15 | isOpen, | |
| 15 | 16 | isPartyRole, |
| 17 | isWaivable, | |
| 16 | 18 | KIND, |
| 17 | 19 | LEAD_MAX, |
| 18 | 20 | LEAD_MIN, |
| @@ -108,6 +110,9 @@ export interface Deadline { | ||
| 108 | 110 | readonly owes: PartyRole; |
| 109 | 111 | readonly what: string; |
| 110 | 112 | 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; | |
| 111 | 116 | /** Days before it is due that its first reminder goes out. */ |
| 112 | 117 | readonly lead_days: number; |
| 113 | 118 | } |
| @@ -212,7 +217,7 @@ function assemble(deal: Deal, rows: Children): DealView { | ||
| 212 | 217 | deadlines: rows.deadlines.map((d) => ({ |
| 213 | 218 | ...d, |
| 214 | 219 | 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, | |
| 216 | 221 | })), |
| 217 | 222 | sent: rows.sent.map((m) => withHref(m, rows.parties)), |
| 218 | 223 | declined: rows.declined, |
| @@ -636,12 +641,45 @@ export function markDone( | ||
| 636 | 641 | ): Result<Deadline> { |
| 637 | 642 | const { dealId, found } = deadlineFor(db, who, input.id); |
| 638 | 643 | 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.")); | |
| 639 | 646 | db.query( |
| 640 | 647 | "UPDATE deadline SET done_at = ?1 WHERE id = ?2", |
| 641 | 648 | ).run(input.done ? new Date().toISOString() : null, input.id); |
| 642 | 649 | return within(db, who, "date.done", dealId, ok(reread(db, input.id))); |
| 643 | 650 | } |
| 644 | 651 | |
| 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 | ||
| 645 | 683 | /** Whether `value` is a lead time: a whole number of days, 1 to 30. */ |
| 646 | 684 | const isLead = (value: unknown): value is number => |
| 647 | 685 | 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): | ||
| 708 | 746 | return { ok: false, field: "dates", message: "Give the dates as { date id: new date }." }; |
| 709 | 747 | const moves: { deadline: Deadline; to: string }[] = []; |
| 710 | 748 | 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)); | |
| 712 | 750 | if (deadline === undefined) |
| 713 | 751 | return { ok: false, field: `due_${key}`, message: `Date ${key} is not an open date of this deal.` }; |
| 714 | 752 | if (!isDate(to)) |
src/ics.ts +4 −4
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import { addDays } from "./dates.ts"; |
| 9 | import { PARTY_LABEL } from "./deadlines.ts"; | |
| 9 | import { isOpen, PARTY_LABEL } from "./deadlines.ts"; | |
| 10 | 10 | import type { DealView } from "./deals.ts"; |
| 11 | 11 | import { signOff, type Agent } from "./reminders.ts"; |
| 12 | 12 | |
| @@ -43,7 +43,7 @@ const stampOf = (stamp: Date): string => stamp.toISOString().replace(/[-:]/g, "" | ||
| 43 | 43 | function events(deal: DealView, host: string, now: string, openOnly: boolean): string[] { |
| 44 | 44 | const lines: string[] = []; |
| 45 | 45 | for (const d of deal.deadlines) { |
| 46 | if (openOnly && d.done_at !== null) continue; | |
| 46 | if (openOnly && !isOpen(d)) continue; | |
| 47 | 47 | const owner = deal.parties.find((p) => p.role === d.owes); |
| 48 | 48 | const who = owner === undefined ? PARTY_LABEL[d.owes] : `${owner.name} (${PARTY_LABEL[d.owes]})`; |
| 49 | 49 | lines.push( |
| @@ -52,12 +52,12 @@ function events(deal: DealView, host: string, now: string, openOnly: boolean): s | ||
| 52 | 52 | `DTSTAMP:${now}`, |
| 53 | 53 | `DTSTART;VALUE=DATE:${compact(d.due)}`, |
| 54 | 54 | `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}`)}`, | |
| 56 | 56 | `DESCRIPTION:${icsText(`${who} owes: ${d.what || d.label}`)}`, |
| 57 | 57 | "STATUS:CONFIRMED", |
| 58 | 58 | "TRANSP:TRANSPARENT", |
| 59 | 59 | ); |
| 60 | if (d.done_at === null) | |
| 60 | if (isOpen(d)) | |
| 61 | 61 | lines.push( |
| 62 | 62 | "BEGIN:VALARM", |
| 63 | 63 | "ACTION:DISPLAY", |
src/mcp.ts +11
| @@ -22,6 +22,7 @@ import { | ||
| 22 | 22 | getDeal, |
| 23 | 23 | listDeals, |
| 24 | 24 | markDone, |
| 25 | waiveDate, | |
| 25 | 26 | amendDeal, |
| 26 | 27 | moveDeadline, |
| 27 | 28 | removeDeadline, |
| @@ -130,6 +131,16 @@ export const tools: readonly Tool[] = [ | ||
| 130 | 131 | }, |
| 131 | 132 | run: (db, who, args) => markDone(db, who, { id: Number(args.id), done: args.done !== false }), |
| 132 | 133 | }, |
| 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 | }, | |
| 133 | 144 | { |
| 134 | 145 | name: "move_date", |
| 135 | 146 | 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) | ||
| 7 | 7 | label: kind === "financing" ? "Financing" : kind === "closing" ? "Closing" : kind, |
| 8 | 8 | due, |
| 9 | 9 | done_at, |
| 10 | waived_at: null, | |
| 10 | 11 | }); |
| 11 | 12 | |
| 12 | 13 | test("an open date before closing is in order; on and after closing are flagged", () => { |
src/order.ts +3 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { short } from "./dates.ts"; |
| 8 | import { isOpen } from "./deadlines.ts"; | |
| 8 | 9 | |
| 9 | 10 | /** An open, non-closing date that falls on or after the closing date. */ |
| 10 | 11 | export interface Conflict { |
| @@ -20,6 +21,7 @@ interface Dated { | ||
| 20 | 21 | readonly label: string; |
| 21 | 22 | readonly due: string; |
| 22 | 23 | readonly done_at: string | null; |
| 24 | readonly waived_at: string | null; | |
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | /** 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[] { | ||
| 27 | 29 | const closing = deadlines.find((d) => d.kind === "closing"); |
| 28 | 30 | if (closing === undefined || closing.done_at !== null) return []; |
| 29 | 31 | 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) | |
| 31 | 33 | .map((d) => ({ deadline_id: d.id, label: d.label, due: d.due, closing: closing.due })); |
| 32 | 34 | } |
| 33 | 35 |
src/pages/amend.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * form comes back with what was typed and the field that was wrong. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { isOpen } from "../deadlines.ts"; | |
| 8 | 9 | import type { DealView } from "../deals.ts"; |
| 9 | 10 | import { escape } from "../http.ts"; |
| 10 | 11 | |
| @@ -16,7 +17,7 @@ export interface AmendState { | ||
| 16 | 17 | } |
| 17 | 18 | |
| 18 | 19 | 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); | |
| 20 | 21 | if (open.length === 0) return ""; |
| 21 | 22 | const { values = {}, problem } = state ?? {}; |
| 22 | 23 | const bad = (field: string): string => |
src/pages/clock.ts +6 −5
| @@ -5,9 +5,9 @@ | ||
| 5 | 5 | * clock, the reminders that go out today. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { addDays, daysBetween, isWeekend, short, spoken, urgency } from "../dates.ts"; | |
| 8 | import { addDays, daysBetween, isWeekend, short, spoken, urgency, urgencyOf } from "../dates.ts"; | |
| 9 | 9 | import type { DealView } from "../deals.ts"; |
| 10 | import { KIND } from "../deadlines.ts"; | |
| 10 | import { isOpen, KIND } from "../deadlines.ts"; | |
| 11 | 11 | import { escape } from "../http.ts"; |
| 12 | 12 | import { agent as defaults } from "../env.ts"; |
| 13 | 13 | import { todaysDrafts, unsent, type Agent } from "../reminders.ts"; |
| @@ -26,7 +26,7 @@ export function span(deals: readonly DealView[], on: string): { start: string; d | ||
| 26 | 26 | let end = addDays(on, 21); |
| 27 | 27 | for (const deal of deals) |
| 28 | 28 | 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); | |
| 30 | 30 | if (d.due > addDays(end, -4)) end = addDays(d.due, 4); |
| 31 | 31 | } |
| 32 | 32 | return { start, days: daysBetween(start, end) + 1 }; |
| @@ -59,7 +59,7 @@ function drawLane(deal: DealView, start: string, on: string): string { | ||
| 59 | 59 | const markers = placed |
| 60 | 60 | .map(({ row, x, i }) => { |
| 61 | 61 | const d = deal.deadlines[i]!; |
| 62 | const u = urgency(d.due, on, d.done_at !== null); | |
| 62 | const u = urgencyOf(d, on); | |
| 63 | 63 | const tag = d.kind === "custom" ? d.label.split(" ")[0]! : KIND[d.kind].tag; |
| 64 | 64 | const flagged = deal.conflicts.some((c) => c.deadline_id === d.id); |
| 65 | 65 | 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: { | ||
| 178 | 178 | const closed = found |
| 179 | 179 | .filter((deal) => deal.closed) |
| 180 | 180 | .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)); | |
| 182 | 182 | const overdue = open.filter((d) => urgency(d.due, on, false) === "overdue").length; |
| 183 | 183 | const soon = open.filter((d) => urgency(d.due, on, false) === "soon").length; |
| 184 | 184 | const { start, days } = span(deals, on); |
| @@ -239,6 +239,7 @@ function render(input: { | ||
| 239 | 239 | <li><span class="dot" data-u="soon"></span>Due within 3 days</li> |
| 240 | 240 | <li><span class="dot" data-u="later"></span>Upcoming</li> |
| 241 | 241 | <li><span class="dot" data-u="done"></span>Done</li> |
| 242 | <li><span class="dot" data-u="waived"></span>Waived</li> | |
| 242 | 243 | </ul> |
| 243 | 244 | </section> |
| 244 | 245 | ${closedCard} |
src/pages/confirm.ts +3 −1
| @@ -17,6 +17,8 @@ export function confirmRemove(input: { | ||
| 17 | 17 | fields?: Readonly<Record<string, string>>; |
| 18 | 18 | /** What the button's accessible name says it removes: "Yes, remove 77 Harbor View Dr". */ |
| 19 | 19 | name: string; |
| 20 | /** The button's words, when it is not a removal: "Yes, waive". */ | |
| 21 | yes?: string; | |
| 20 | 22 | small?: boolean; |
| 21 | 23 | class?: string; |
| 22 | 24 | }): string { |
| @@ -26,6 +28,6 @@ export function confirmRemove(input: { | ||
| 26 | 28 | return `<details class="confirm${input.class === undefined ? "" : ` ${input.class}`}"> |
| 27 | 29 | <summary class="button button-quiet${input.small ? " button-small" : ""}">${escape(input.summary)}</summary> |
| 28 | 30 | <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> | |
| 30 | 32 | </details>`; |
| 31 | 33 | } |
src/pages/sheet.ts +29 −8
| @@ -6,8 +6,8 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | 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"; | |
| 11 | 11 | import { escape } from "../http.ts"; |
| 12 | 12 | import { confirmRemove } from "./confirm.ts"; |
| 13 | 13 | import { memoizer, print } from "../memo.ts"; |
| @@ -31,6 +31,7 @@ export const opens = (deal: DealView, d: DeadlineView): string => | ||
| 31 | 31 | |
| 32 | 32 | export const URGENCY_LABEL: Readonly<Record<Urgency, string>> = { |
| 33 | 33 | done: "Done", |
| 34 | waived: "Waived", | |
| 34 | 35 | overdue: "Overdue", |
| 35 | 36 | soon: "Due soon", |
| 36 | 37 | later: "Upcoming", |
| @@ -38,6 +39,7 @@ export const URGENCY_LABEL: Readonly<Record<Urgency, string>> = { | ||
| 38 | 39 | |
| 39 | 40 | /** "Due Thu, Oct 15 · in 3 days", or "Done". */ |
| 40 | 41 | 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)}`; | |
| 41 | 43 | if (d.done_at !== null) return `Done · was due ${spoken(d.due)}`; |
| 42 | 44 | return `Due ${spoken(d.due)} · ${relative(d.due, on)}`; |
| 43 | 45 | } |
| @@ -57,7 +59,7 @@ export const rollForm = (d: DeadlineView, to: string): string => | ||
| 57 | 59 | </form>`; |
| 58 | 60 | |
| 59 | 61 | 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); | |
| 61 | 63 | return `<span class="badge" data-u="${u}">${URGENCY_LABEL[u]}</span>`; |
| 62 | 64 | }; |
| 63 | 65 | |
| @@ -157,9 +159,11 @@ export const draftLink = (draft: Draft, on: string): string => | ||
| 157 | 159 | export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: string, agent: Agent = defaults): string { |
| 158 | 160 | const id = sheetId(d); |
| 159 | 161 | 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) : []; | |
| 161 | 163 | 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 | |
| 163 | 167 | ? `<p class="muted">Done, so no reminders go out.</p>` |
| 164 | 168 | : drafts.length === 0 |
| 165 | 169 | ? `<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: | ||
| 180 | 184 | .join("")}</ul></section>`; |
| 181 | 185 | const actions = may |
| 182 | 186 | ? `<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 })} | |
| 184 | 193 | <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 | } | |
| 186 | 207 | <form class="move" method="post" action="/deadlines/${d.id}/move">${hidden({ to })} |
| 187 | 208 | <label>New date<input class="input" type="date" name="due" value="${escape(d.due)}" required></label> |
| 188 | 209 | <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: | ||
| 220 | 241 | ${conflictLines(deal, d)} |
| 221 | 242 | ${nonBusinessLine(d)}${may ? rollForm(d, to) : ""} |
| 222 | 243 | ${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> | |
| 224 | 245 | ${actions} |
| 225 | 246 | </div>`; |
| 226 | 247 | } |
src/people.test.ts +1 −1
| @@ -9,7 +9,7 @@ const deal = (id: number, address: string, parties: [number, string, string, str | ||
| 9 | 9 | address, |
| 10 | 10 | closed, |
| 11 | 11 | 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 })), | |
| 13 | 13 | }) as unknown as DealView; |
| 14 | 14 | |
| 15 | 15 | const deals = [ |
src/people.ts +2 −2
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | |
| 7 | 7 | import { urgency, type Urgency } from "./dates.ts"; |
| 8 | 8 | 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"; | |
| 10 | 10 | |
| 11 | 11 | export interface Owed { |
| 12 | 12 | readonly deal_id: number; |
| @@ -48,7 +48,7 @@ export function people(deals: readonly DealView[], on: string): Person[] { | ||
| 48 | 48 | // A closed deal is off the clock: nothing on it is chased. |
| 49 | 49 | if (deal.closed) continue; |
| 50 | 50 | 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; | |
| 52 | 52 | one.owes.set(d.id, { |
| 53 | 53 | deal_id: deal.id, |
| 54 | 54 | address: deal.address, |
src/progress.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import { daysBetween } from "./dates.ts"; |
| 8 | import { isSettled } from "./deadlines.ts"; | |
| 8 | 9 | import type { DealView } from "./deals.ts"; |
| 9 | 10 | |
| 10 | 11 | export interface Progress { |
| @@ -22,7 +23,7 @@ export function progress( | ||
| 22 | 23 | let done = 0; |
| 23 | 24 | let overdue = 0; |
| 24 | 25 | for (const d of deal.deadlines) { |
| 25 | if (d.done_at !== null) done++; | |
| 26 | if (isSettled(d)) done++; | |
| 26 | 27 | else if (d.due < on) overdue++; |
| 27 | 28 | } |
| 28 | 29 | return { |
src/reminders.ts +8 −7
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | |
| 11 | 11 | import { addDays, relative, spoken, today } from "./dates.ts"; |
| 12 | 12 | 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"; | |
| 14 | 14 | import type { DealView, DeadlineView, Move, Moment, Party } from "./deals.ts"; |
| 15 | 15 | |
| 16 | 16 | export interface Agent { |
| @@ -114,7 +114,7 @@ function noticeFor(deal: DealView, deadline: DeadlineView, party: Party): Notice | ||
| 114 | 114 | if (last.amendment === 0) return { items: [{ deadline, move: last }], key: last.id }; |
| 115 | 115 | const told = (d: DeadlineView): boolean => recipients(deal, d, "moved").some((p) => p.id === party.id); |
| 116 | 116 | const items = deal.deadlines |
| 117 | .filter((d) => d.done_at === null && told(d)) | |
| 117 | .filter((d) => isOpen(d) && told(d)) | |
| 118 | 118 | .flatMap((d) => { |
| 119 | 119 | const move = lastMove(d); |
| 120 | 120 | return move !== undefined && move.amendment === last.amendment ? [{ deadline: d, move }] : []; |
| @@ -175,7 +175,7 @@ export function drafts(deal: DealView, agent: Agent): readonly Draft[] { | ||
| 175 | 175 | if (deal.closed) return []; |
| 176 | 176 | return remembered(`${JSON.stringify(agent)}|${print(deal)}`, () => |
| 177 | 177 | deal.deadlines |
| 178 | .filter((d) => d.done_at === null) | |
| 178 | .filter(isOpen) | |
| 179 | 179 | .flatMap((deadline) => draftsFor(deal, deadline, agent)), |
| 180 | 180 | ); |
| 181 | 181 | } |
| @@ -235,7 +235,7 @@ const NEXT_MAX = 4; | ||
| 235 | 235 | export function standing(deal: DealView): number { |
| 236 | 236 | let h = 2166136261; |
| 237 | 237 | 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}`) | |
| 239 | 239 | .sort() |
| 240 | 240 | .join("|"); |
| 241 | 241 | 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; | ||
| 253 | 253 | /** The words of a status update to one party. */ |
| 254 | 254 | function statusWords(deal: DealView, party: Party, agent: Agent): { subject: string; body: string } { |
| 255 | 255 | 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)); | |
| 258 | 258 | const owner = (d: DeadlineView): string => deal.parties.find((p) => p.role === d.owes)?.name ?? PARTY_LABEL[d.owes]; |
| 259 | 259 | const next = open.slice(0, NEXT_MAX).map((d) => `• ${d.label}: ${spoken(d.due)} (${owner(d)} · ${PARTY_LABEL[d.owes].toLowerCase()})`); |
| 260 | 260 | 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"); | |
| 262 | 262 | return { |
| 263 | 263 | subject: `${deal.address} — where things stand`, |
| 264 | 264 | 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[] { | ||
| 308 | 308 | |
| 309 | 309 | /** The draft of `moment` that `party` has on `deadline`, if any: a reminder, or the deal's status update on its closing date. */ |
| 310 | 310 | export function draftOfMoment(deal: DealView, deadline: DeadlineView, agent: Agent, party: Party, moment: Moment): Draft | undefined { |
| 311 | if (moment !== "status" && !isOpen(deadline)) return undefined; | |
| 311 | 312 | const these = moment === "status" ? (deadline.kind === "closing" ? statusDrafts(deal, agent) : []) : draftsFor(deal, deadline, agent); |
| 312 | 313 | return these.find((r) => r.party_id === party.id && r.moment === moment); |
| 313 | 314 | } |
src/routes.ts +35
| @@ -50,6 +50,7 @@ import { | ||
| 50 | 50 | withConflicts, |
| 51 | 51 | listDeals, |
| 52 | 52 | markDone, |
| 53 | waiveDate, | |
| 53 | 54 | mayOpen, |
| 54 | 55 | openDealAt, |
| 55 | 56 | plan, |
| @@ -210,6 +211,8 @@ export const DEAL: Schema = { | ||
| 210 | 211 | owes: ROLE, |
| 211 | 212 | what: { type: "string" }, |
| 212 | 213 | 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." }, | |
| 213 | 216 | moves: { type: "array", items: { type: "object" } }, |
| 214 | 217 | nonBusinessDay: { |
| 215 | 218 | type: ["object", "null"], |
| @@ -861,6 +864,19 @@ export const routes: readonly Route[] = [ | ||
| 861 | 864 | return done(markDone(c.db, c.who, { id: Number(c.params.id), done: isDone }), backTo(f.to), isDone ? "Marked done." : "Reopened."); |
| 862 | 865 | }, |
| 863 | 866 | }, |
| 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 | }, | |
| 864 | 880 | { |
| 865 | 881 | method: "POST", |
| 866 | 882 | path: "/deadlines/:id/move", |
| @@ -1226,6 +1242,25 @@ export const routes: readonly Route[] = [ | ||
| 1226 | 1242 | answer: { type: "object", properties: { id: { type: "integer" }, lead_days: { type: "integer" } }, required: ["id", "lead_days"] }, |
| 1227 | 1243 | }, |
| 1228 | 1244 | }, |
| 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 | }, | |
| 1229 | 1264 | { |
| 1230 | 1265 | method: "DELETE", |
| 1231 | 1266 | path: "/api/deals/:id/deadlines/:deadline", |
src/sample.test.ts +5 −4
| @@ -11,8 +11,8 @@ import { isUntouched, shiftSample, type SampleDates } from "./sample.ts"; | ||
| 11 | 11 | const dates: SampleDates = { |
| 12 | 12 | contractDate: "2026-09-01", |
| 13 | 13 | 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 }, | |
| 16 | 16 | ], |
| 17 | 17 | moves: [{ id: 7, fromDue: "2026-09-22", toDue: "2026-10-03" }], |
| 18 | 18 | }; |
| @@ -21,8 +21,8 @@ test("every date of a sample moves by the days since its anchor, together", () = | ||
| 21 | 21 | const a = shiftSample(dates, "2026-10-01", "2026-10-31"); |
| 22 | 22 | expect(a.contractDate).toBe("2026-10-01"); |
| 23 | 23 | 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 }, | |
| 26 | 26 | ]); |
| 27 | 27 | expect(a.moves).toEqual([{ id: 7, fromDue: "2026-10-22", toDue: "2026-11-02" }]); |
| 28 | 28 | // 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", () => { | ||
| 39 | 39 | customs: 1, |
| 40 | 40 | reminders: 0, |
| 41 | 41 | 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], | |
| 42 | 43 | moveAuthors: ["Sample data"], |
| 43 | 44 | }; |
| 44 | 45 | expect(isUntouched(state, "2026-10-01")).toBe(true); |
src/sample.ts +15 −5
| @@ -23,6 +23,8 @@ interface Sample { | ||
| 23 | 23 | readonly lengths?: Partial<typeof BRIEF_LENGTHS>; |
| 24 | 24 | readonly parties: readonly [PartyRole, string, string][]; |
| 25 | 25 | readonly done?: readonly string[]; |
| 26 | /** Kinds the buyer waived on purpose. */ | |
| 27 | readonly waived?: readonly string[]; | |
| 26 | 28 | readonly custom?: readonly [string, number, PartyRole, string][]; |
| 27 | 29 | readonly moved?: readonly [string, number, string]; |
| 28 | 30 | /** 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[] = [ | ||
| 91 | 93 | ["lender", "Owen Brandt, First Keel Bank", "[email protected]"], |
| 92 | 94 | ["other_agent", "Jordan Ellis, Crestline Homes", "(555) 014-2290"], |
| 93 | 95 | ], |
| 96 | waived: ["appraisal"], | |
| 94 | 97 | }, |
| 95 | 98 | ]; |
| 96 | 99 | |
| @@ -100,7 +103,7 @@ const DONE_TIME = "T17:00:00.000Z"; | ||
| 100 | 103 | /** The dates of one sample deal, as plain data. */ |
| 101 | 104 | export interface SampleDates { |
| 102 | 105 | 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 }[]; | |
| 104 | 107 | readonly moves: readonly { readonly id: number; readonly fromDue: string; readonly toDue: string }[]; |
| 105 | 108 | } |
| 106 | 109 | |
| @@ -119,6 +122,7 @@ export function shiftSample(dates: SampleDates, anchor: string, on: string): Sam | ||
| 119 | 122 | id: d.id, |
| 120 | 123 | due: addDays(d.due, days), |
| 121 | 124 | 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), | |
| 122 | 126 | })), |
| 123 | 127 | moves: dates.moves.map((m) => ({ id: m.id, fromDue: addDays(m.fromDue, days), toDue: addDays(m.toDue, days) })), |
| 124 | 128 | }; |
| @@ -132,6 +136,7 @@ export interface SampleState { | ||
| 132 | 136 | readonly customs: number; |
| 133 | 137 | readonly reminders: number; |
| 134 | 138 | readonly doneAts: readonly (string | null)[]; |
| 139 | readonly waivedAts: readonly (string | null)[]; | |
| 135 | 140 | readonly moveAuthors: readonly string[]; |
| 136 | 141 | } |
| 137 | 142 | |
| @@ -146,6 +151,8 @@ export function isUntouched(state: SampleState, anchor: string): boolean { | ||
| 146 | 151 | state.reminders === 0 && |
| 147 | 152 | state.doneAts.every((d) => d === null || d === marker) && |
| 148 | 153 | 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) && | |
| 149 | 156 | state.moveAuthors.length === (s.moved === undefined ? 0 : 1) && |
| 150 | 157 | state.moveAuthors.every((a) => a === SAMPLE.name) |
| 151 | 158 | ); |
| @@ -166,8 +173,8 @@ export function refresh(db: Database, on = today()): void { | ||
| 166 | 173 | "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", |
| 167 | 174 | ).all(SAMPLE.id); |
| 168 | 175 | 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", | |
| 171 | 178 | ).all(deal.id); |
| 172 | 179 | const moves = db.query<{ id: number; from_due: string; to_due: string; by_name: string }, [number]>( |
| 173 | 180 | "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 { | ||
| 184 | 191 | customs: deadlines.filter((d) => d.kind === "custom").length, |
| 185 | 192 | reminders, |
| 186 | 193 | doneAts: deadlines.map((d) => d.done_at), |
| 194 | waivedAts: deadlines.map((d) => d.waived_at), | |
| 187 | 195 | moveAuthors: moves.map((m) => m.by_name), |
| 188 | 196 | }; |
| 189 | 197 | if (!isUntouched(state, anchor)) continue; |
| 190 | 198 | const shifted = shiftSample( |
| 191 | 199 | { |
| 192 | 200 | 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 })), | |
| 194 | 202 | moves: moves.map((m) => ({ id: m.id, fromDue: m.from_due, toDue: m.to_due })), |
| 195 | 203 | }, |
| 196 | 204 | anchor, |
| 197 | 205 | on, |
| 198 | 206 | ); |
| 199 | 207 | 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); | |
| 201 | 209 | 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); |
| 202 | 210 | // The sample's sent reminder follows its date, so it stays "yesterday's". |
| 203 | 211 | const days = `+${daysBetween(anchor, on)} days`; |
| @@ -225,6 +233,8 @@ function writeSamples(db: Database, on: string): void { | ||
| 225 | 233 | db.query("INSERT INTO party (deal_id, role, name, contact) VALUES (?1, ?2, ?3, ?4)").run(deal.id, role, name, contact); |
| 226 | 234 | for (const kind of s.done ?? []) |
| 227 | 235 | 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); | |
| 228 | 238 | for (const [label, days, owes, what] of s.custom ?? []) |
| 229 | 239 | 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); |
| 230 | 240 | if (s.sent !== undefined) { |
src/security.ts +2 −2
| @@ -98,8 +98,8 @@ export function doorOf( | ||
| 98 | 98 | const verb = ROW_VERB[method]; |
| 99 | 99 | return verb === undefined ? undefined : { resource, verb }; |
| 100 | 100 | } |
| 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)))) | |
| 103 | 103 | return method === "PATCH" || method === "DELETE" || method === "POST" ? { resource, verb: "update" } : undefined; |
| 104 | 104 | } |
| 105 | 105 | 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 () => | ||
| 178 | 178 | "this_week", |
| 179 | 179 | "list_people", |
| 180 | 180 | "mark_done", |
| 181 | "waive_date", | |
| 181 | 182 | "move_date", |
| 182 | 183 | "set_reminder_lead", |
| 183 | 184 | "amend_deal", |
src/terminal.ts +20 −13
| @@ -12,7 +12,7 @@ | ||
| 12 | 12 | * profile your name, brokerage, phone and email (I); e edits them, U goes back to the defaults |
| 13 | 13 | * 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 |
| 14 | 14 | * |
| 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 | |
| 16 | 16 | * (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 |
| 17 | 17 | * deal (address, buyer, seller, contract and closing dates); d, r and b move |
| 18 | 18 | * between views; esc cancels a prompt; q leaves. / finds a deal by address or |
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | |
| 22 | 22 | import type { Database } from "bun:sqlite"; |
| 23 | 23 | 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"; | |
| 25 | 25 | import { |
| 26 | 26 | addDeadline, |
| 27 | 27 | addParty, |
| @@ -35,6 +35,7 @@ import { | ||
| 35 | 35 | closedOn, |
| 36 | 36 | listDeals, |
| 37 | 37 | markDone, |
| 38 | waiveDate, | |
| 38 | 39 | mayOpen, |
| 39 | 40 | planFor, |
| 40 | 41 | plannedDates, |
| @@ -58,7 +59,7 @@ import { | ||
| 58 | 59 | import { find, FIND_MAX, query } from "./find.ts"; |
| 59 | 60 | import { mayRestore, restoreSamples } from "./actions.ts"; |
| 60 | 61 | 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"; | |
| 62 | 63 | import { agentOf, getProfile, setProfile, useDefaults } from "./profile.ts"; |
| 63 | 64 | import { permit } from "./contract.ts"; |
| 64 | 65 | 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`; | ||
| 75 | 76 | const bold = (s: string): string => `${esc}1m${s}${esc}0m`; |
| 76 | 77 | /** Audit rows to a screen. */ |
| 77 | 78 | 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" }; | |
| 79 | 80 | const tint = (u: Urgency, s: string): string => `${esc}${COLOUR[u]}m${s}${esc}0m`; |
| 80 | 81 | |
| 81 | 82 | type View = "dates" | "week" | "people" | "reminders" | "deal" | "messages" | "timeline" | "profile" | "activity"; |
| @@ -141,7 +142,7 @@ export function terminal( | ||
| 141 | 142 | if (view === "week") return thisWeek(deals(), on()).map(({ deal, deadline }) => ({ deal, date: deadline })); |
| 142 | 143 | return deals() |
| 143 | 144 | .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 })), | |
| 145 | 146 | ) |
| 146 | 147 | .sort((a, b) => a.date.due.localeCompare(b.date.due) || a.date.id - b.date.id); |
| 147 | 148 | }; |
| @@ -180,14 +181,20 @@ export function terminal( | ||
| 180 | 181 | |
| 181 | 182 | function onDate(key: string): boolean { |
| 182 | 183 | 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; | |
| 184 | 185 | if (row === undefined) { |
| 185 | 186 | said = "No date here."; |
| 186 | 187 | return true; |
| 187 | 188 | } |
| 188 | 189 | const { deal, date } = row; |
| 189 | 190 | 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}.`); | |
| 191 | 198 | if (key === "m") |
| 192 | 199 | ask(deal, [`New date for ${date.label} (YYYY-MM-DD, now ${date.due})`, "Why it moved"], ([due, reason]) => |
| 193 | 200 | 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( | ||
| 243 | 250 | report(updateDeal(db, me, { id: deal.id, address }), `Address is now ${address!.trim()}.`), |
| 244 | 251 | ); |
| 245 | 252 | if (key === "M") { |
| 246 | const open = deal.deadlines.filter((d) => d.done_at === null); | |
| 253 | const open = deal.deadlines.filter(isOpen); | |
| 247 | 254 | ask(deal, [...open.map((d) => `${d.label} (now ${d.due}; blank keeps it)`), "Why the dates moved"], (answers) => { |
| 248 | 255 | const dates = Object.fromEntries(open.flatMap((d, i) => (answers[i]!.trim() === "" ? [] : [[String(d.id), answers[i]!.trim()]]))); |
| 249 | 256 | const count = Object.keys(dates).length; |
| @@ -589,14 +596,14 @@ export function terminal( | ||
| 589 | 596 | |
| 590 | 597 | const dateLine = (row: Row, i: number, withDeal: boolean): string => { |
| 591 | 598 | 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)}`); | |
| 594 | 601 | const who = owner(deal, date); |
| 595 | 602 | const label = view === "week" ? `${date.label} — ${deal.address} · ${who.name ?? who.role}` : withDeal ? `${date.label} — ${deal.address}` : date.label; |
| 596 | 603 | const text = label + (deal.closed && withDeal ? dim(" (closed)") : ""); |
| 597 | 604 | const moved = date.moves.length > 0 ? dim(` moved: ${date.moves.at(-1)!.reason}`) : ""; |
| 598 | 605 | 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`) : ""; | |
| 600 | 607 | return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${flag}${lead}${moved}`; |
| 601 | 608 | }; |
| 602 | 609 | |
| @@ -753,8 +760,8 @@ export function terminal( | ||
| 753 | 760 | : view === "timeline" |
| 754 | 761 | ? "b back to the deal · d dates · q quit" |
| 755 | 762 | : 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`; | |
| 758 | 765 | lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys)); |
| 759 | 766 | } |
| 760 | 767 | return lines; |
src/timeline.ts +4 −3
| @@ -5,15 +5,16 @@ | ||
| 5 | 5 | * internal — no notes, drafts, reasons or contacts. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { spoken, urgency, type Urgency } from "./dates.ts"; | |
| 8 | import { spoken, urgencyOf, type Urgency } from "./dates.ts"; | |
| 9 | 9 | import type { DealView } from "./deals.ts"; |
| 10 | 10 | import { owner } from "./week.ts"; |
| 11 | 11 | |
| 12 | export type TimelineStatus = "Done" | "Upcoming" | "Overdue"; | |
| 12 | export type TimelineStatus = "Done" | "Waived" | "Upcoming" | "Overdue"; | |
| 13 | 13 | |
| 14 | 14 | /** Words first, so black and white reads the same as colour; the mark is only a helper. */ |
| 15 | 15 | const STATUS: Readonly<Record<Urgency, { mark: string; word: TimelineStatus }>> = { |
| 16 | 16 | done: { mark: "✓", word: "Done" }, |
| 17 | waived: { mark: "–", word: "Waived" }, | |
| 17 | 18 | overdue: { mark: "!", word: "Overdue" }, |
| 18 | 19 | soon: { mark: "○", word: "Upcoming" }, |
| 19 | 20 | later: { mark: "○", word: "Upcoming" }, |
| @@ -35,7 +36,7 @@ export interface TimelineRow { | ||
| 35 | 36 | |
| 36 | 37 | export function timelineRows(deal: DealView, on: string): TimelineRow[] { |
| 37 | 38 | return deal.deadlines.map((d) => { |
| 38 | const u = urgency(d.due, on, d.done_at !== null); | |
| 39 | const u = urgencyOf(d, on); | |
| 39 | 40 | const { name, role } = owner(deal, d); |
| 40 | 41 | return { label: d.label, due: d.due, spoken: spoken(d.due), role, name, status: STATUS[u].word, mark: STATUS[u].mark, urgency: u }; |
| 41 | 42 | }); |
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"; | ||
| 2 | 2 | import { thisWeek } from "./week.ts"; |
| 3 | 3 | |
| 4 | 4 | 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 }); | |
| 6 | 6 | const deals = [ |
| 7 | 7 | { address: "B Street", deadlines: [d("2026-11-09"), d("2026-11-10"), d("2026-10-30")] }, |
| 8 | 8 | { 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 @@ | ||
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | 6 | import { addDays } from "./dates.ts"; |
| 7 | import { PARTY_LABEL, type PartyRole } from "./deadlines.ts"; | |
| 7 | import { isOpen, PARTY_LABEL, type PartyRole } from "./deadlines.ts"; | |
| 8 | 8 | |
| 9 | 9 | /** How many days past today still count as this week. */ |
| 10 | 10 | export const WEEK = 7; |
| @@ -21,7 +21,7 @@ export interface WeekItem<Deal, D> { | ||
| 21 | 21 | readonly deadline: D; |
| 22 | 22 | } |
| 23 | 23 | |
| 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>>( | |
| 25 | 25 | deals: readonly Deal[], |
| 26 | 26 | on: string, |
| 27 | 27 | ): WeekItem<Deal, D>[] { |
| @@ -29,7 +29,7 @@ export function thisWeek<D extends { due: string; done_at: string | null }, Deal | ||
| 29 | 29 | return deals |
| 30 | 30 | .filter((deal) => deal.closed !== true) |
| 31 | 31 | .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 })), | |
| 33 | 33 | ) |
| 34 | 34 | .sort( |
| 35 | 35 | (a, b) => |
static/app.css +3
| @@ -461,6 +461,8 @@ footer code { | ||
| 461 | 461 | background: var(); |
| 462 | 462 | } |
| 463 | 463 | .marker[data-u="done"], |
| 464 | .marker[data-u="waived"], | |
| 465 | .badge[data-u="waived"], | |
| 464 | 466 | .badge[data-u="done"] { |
| 465 | 467 | color: var(); |
| 466 | 468 | background: var(); |
| @@ -484,6 +486,7 @@ footer code { | ||
| 484 | 486 | .dot[data-u="overdue"] { |
| 485 | 487 | background: var(); |
| 486 | 488 | } |
| 489 | .dot[data-u="waived"], | |
| 487 | 490 | .dot[data-u="done"] { |
| 488 | 491 | background: var(); |
| 489 | 492 | } |
new above
offline