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

A date that slips past due without being marked done drafts a follow-up to whoever owes it, which the agent approves like any reminder #35

Merged opened this

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

Merged

mason/deal-clock:mason/25-a-date-that-slips-past-due-without-being → main 3 commits fork 3 threads · 3 unresolved

  • Merged. mason/25-a-date-that-slips-past-due-without-being was merged into main as b83509d.

Review

Sign in to review this change.
14 files changed +227 −38
README.md +4 −2
@@ -29,8 +29,10 @@ for the same list; over MCP, an agent asks for the `this_week` tool.
2929 still ahead).
3030 2. **Open a marker.** Tap the red inspection marker on Harbor View. A sheet
3131 opens with the date, who owes it (the buyer), what is owed, and the reminders
32 for each party, grouped as three days before and the morning of. It also
33 has two buttons: Mark done, and Move this date.
32 for each party, grouped as three days before, the morning of, and an
33 Overdue follow-up to the buyer, because the date passed without being marked
34 done (it waits under Reminders for today until you send or decline it). It
35 also has two buttons: Mark done, and Move this date.
3436 3. **Read and edit a reminder.** In the sheet, tap a party's reminder. You
3537 see the words it would send, in a subject field and a message field,
3638 already filled in. Change the message; the subject can run to 150
contract/openapi.json +10 −5
@@ -528,7 +528,8 @@
528528 "moment": {
529529 "enum": [
530530 "before",
531 "day_of"
531 "day_of",
532 "late"
532533 ]
533534 },
534535 "reason": {
@@ -621,7 +622,8 @@
621622 "moment": {
622623 "enum": [
623624 "before",
624 "day_of"
625 "day_of",
626 "late"
625627 ]
626628 }
627629 },
@@ -1068,7 +1070,8 @@
10681070 "moment": {
10691071 "enum": [
10701072 "before",
1071 "day_of"
1073 "day_of",
1074 "late"
10721075 ]
10731076 },
10741077 "due": {
@@ -1117,7 +1120,8 @@
11171120 "moment": {
11181121 "enum": [
11191122 "before",
1120 "day_of"
1123 "day_of",
1124 "late"
11211125 ]
11221126 },
11231127 "due": {
@@ -1192,7 +1196,8 @@
11921196 "moment": {
11931197 "enum": [
11941198 "before",
1195 "day_of"
1199 "day_of",
1200 "late"
11961201 ]
11971202 },
11981203 "on": {
src/db.test.ts +23
@@ -88,3 +88,26 @@ test("a database whose reminder columns came from another migration order still
8888 expect(check(db).version).toBe(migrations.length);
8989 expect(db.query("SELECT subject, body FROM reminder WHERE sample = 0").all()).toEqual([]);
9090 });
91
92 test("the migration that accepts the late moment keeps the rows of the old schema", () => {
93 const dir = mkdtempSync(join(tmpdir(), "app-db-late-"));
94 const raw = new Database(join(dir, "app.db"));
95 raw.exec("PRAGMA foreign_keys = ON");
96 const last = migrations.length - 1;
97 raw.exec("CREATE TABLE schema_version (version INTEGER PRIMARY KEY, applied_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')))");
98 migrations.slice(0, last).forEach((sql, i) => {
99 raw.exec(sql);
100 raw.query("INSERT INTO schema_version (version) VALUES (?1)").run(i + 1);
101 });
102 raw.exec(`INSERT INTO deal (id, address, contract_date, author_id, author_name) VALUES (1, 'A St', '2026-01-01', 'u', 'U');
103 INSERT INTO party (id, deal_id, role, name) VALUES (1, 1, 'buyer', 'Ann');
104 INSERT INTO deadline (id, deal_id, kind, label, due, owes) VALUES (1, 1, 'inspection', 'Inspection', '2026-01-10', 'buyer');
105 INSERT INTO reminder (deal_id, deadline_id, party_id, label, party_name, party_role, moment, due, by_name, subject, body) VALUES (1, 1, 1, 'Inspection', 'Ann', 'buyer', 'before', '2026-01-10', 'Dana', 'S', 'B');
106 INSERT INTO reminder_declined (deal_id, deadline_id, party_id, label, party_name, moment, due, reason, by_name) VALUES (1, 1, 1, 'Inspection', 'Ann', 'day_of', '2026-01-10', 'Spoke by phone', 'Dana')`);
107 expect(() => raw.exec("INSERT INTO reminder (deal_id, deadline_id, party_id, label, party_name, moment, due, by_name) VALUES (1, 1, 1, 'I', 'Ann', 'late', '2026-01-10', 'D')")).toThrow();
108 migrate(raw);
109 expect(raw.query("SELECT moment, subject, body, party_role FROM reminder").all()).toEqual([{ moment: "before", subject: "S", body: "B", party_role: "buyer" }]);
110 expect(raw.query("SELECT moment, reason FROM reminder_declined").all()).toEqual([{ moment: "day_of", reason: "Spoke by phone" }]);
111 raw.exec("INSERT INTO reminder (deal_id, deadline_id, party_id, label, party_name, moment, due, by_name) VALUES (1, 1, 1, 'I', 'Ann', 'late', '2026-01-10', 'D')");
112 expect(migrate(raw)).toBe(migrations.length);
113 });
src/db.ts +45
@@ -153,6 +153,51 @@ export const migrations: string[] = [
153153 // person's.
154154 `ALTER TABLE reminder ADD COLUMN sample INTEGER NOT NULL DEFAULT 0;
155155 UPDATE reminder SET sample = 1 WHERE by_name = 'Sample data' AND deal_id IN (SELECT id FROM deal WHERE author_id = 'sample')`,
156 // An overdue follow-up is a third moment, `late`. SQLite cannot alter a
157 // CHECK, so both tables are rebuilt with their rows kept; the old tables
158 // are named only inside this one migration, and schema_version means it runs
159 // once.
160 `CREATE TABLE reminder_new (
161 id INTEGER PRIMARY KEY,
162 deal_id INTEGER NOT NULL REFERENCES deal (id) ON DELETE CASCADE,
163 deadline_id INTEGER NOT NULL,
164 party_id INTEGER NOT NULL,
165 label TEXT NOT NULL,
166 party_name TEXT NOT NULL,
167 moment TEXT NOT NULL CHECK (moment IN ('before', 'day_of', 'late')),
168 due TEXT NOT NULL,
169 by_name TEXT NOT NULL,
170 subject TEXT NOT NULL DEFAULT '',
171 body TEXT NOT NULL DEFAULT '',
172 sent_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
173 party_role TEXT NOT NULL DEFAULT '',
174 sample INTEGER NOT NULL DEFAULT 0,
175 UNIQUE (deadline_id, party_id, moment, due)
176 );
177 INSERT INTO reminder_new (id, deal_id, deadline_id, party_id, label, party_name, moment, due, by_name, subject, body, sent_at, party_role, sample)
178 SELECT id, deal_id, deadline_id, party_id, label, party_name, moment, due, by_name, subject, body, sent_at, party_role, sample FROM reminder;
179 DROP TABLE reminder;
180 ALTER TABLE reminder_new RENAME TO reminder;
181 CREATE INDEX reminder_deal ON reminder (deal_id);
182 CREATE TABLE reminder_declined_new (
183 id INTEGER PRIMARY KEY,
184 deal_id INTEGER NOT NULL REFERENCES deal (id) ON DELETE CASCADE,
185 deadline_id INTEGER NOT NULL,
186 party_id INTEGER NOT NULL,
187 label TEXT NOT NULL,
188 party_name TEXT NOT NULL,
189 moment TEXT NOT NULL CHECK (moment IN ('before', 'day_of', 'late')),
190 due TEXT NOT NULL,
191 reason TEXT NOT NULL CHECK (length(reason) BETWEEN 1 AND 200),
192 by_name TEXT NOT NULL,
193 at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ', 'now')),
194 UNIQUE (deadline_id, party_id, moment, due)
195 );
196 INSERT INTO reminder_declined_new (id, deal_id, deadline_id, party_id, label, party_name, moment, due, reason, by_name, at)
197 SELECT id, deal_id, deadline_id, party_id, label, party_name, moment, due, reason, by_name, at FROM reminder_declined;
198 DROP TABLE reminder_declined;
199 ALTER TABLE reminder_declined_new RENAME TO reminder_declined;
200 CREATE INDEX reminder_declined_deal ON reminder_declined (deal_id)`,
156201 ];
157202
158203 export function openDb(dir = dataDir): Database {
src/deals.test.ts +54 −1
@@ -28,7 +28,7 @@ import {
2828 import { isClosed } from "./deadlines.ts";
2929 import { openDb } from "./db.ts";
3030 import { calendar, fold, icsText } from "./ics.ts";
31 import { drafts, dueOn, recipients } from "./reminders.ts";
31 import { drafts, dueOn, pending, recipients } from "./reminders.ts";
3232 import type { Who } from "./who.ts";
3333
3434 const db = openDb(mkdtempSync(join(tmpdir(), "app-deals-")));
@@ -199,6 +199,7 @@ test("reminders: three days before and the morning of, drafted in words, marked
199199 ["Sam Seller", "before", today()],
200200 ["Ann Buyer", "day_of", inspection.due],
201201 ["Sam Seller", "day_of", inspection.due],
202 ["Ann Buyer", "late", addDays(inspection.due, 1)],
202203 ]);
203204 const buyer = mine[0]!;
204205 expect(buyer.body).toContain("Hi Ann,");
@@ -438,3 +439,55 @@ test("a deal is closed when its Closing date is marked done, and open again when
438439 expect(isClosed([{ kind: "closing", done_at: "2026-11-02T10:00:00.000Z" }])).toBe(true);
439440 expect(isClosed([{ kind: "closing", done_at: null }, { kind: "custom", done_at: "x" }])).toBe(false);
440441 });
442
443 test("an overdue follow-up: the morning after, to whoever owes the date alone, until it is done or moved", () => {
444 const deal = open({ contractDate: addDays(today(), -10), closingDate: addDays(today(), 30), lengths: { inspection: "8" } });
445 const inspection = due(deal, "inspection"); // due two days ago
446 const lates = (d: DealView) => drafts(d, agent).filter((r) => r.deadline_id === inspection.id && r.moment === "late");
447 expect(lates(deal).map((r) => [r.party_name, r.on, r.sent_at])).toEqual([["Ann Buyer", addDays(inspection.due, 1), null]]);
448 const draft = lates(deal)[0]!;
449 expect(draft.body).toContain("was due");
450 expect(draft.body).toContain("update");
451 expect(draft.body).toContain("Dana Whitfield, Harbor & Pine Realty");
452 expect(dueOn([deal], addDays(inspection.due, 1), agent).filter((r) => r.moment === "late").length).toBe(1);
453
454 const ask = { deadlineId: inspection.id, partyId: draft.party_id, moment: "late" };
455 expect(sendReminder(db, alice, { ...ask, subject: "Where is it?", body: "My own words" }).ok).toBe(true);
456 const kept = lates(fresh(deal.id))[0]!;
457 expect(kept.sent_at).not.toBeNull();
458 expect(kept.body).toBe("My own words");
459 expect(db.query("SELECT moment FROM reminder WHERE deadline_id = ?1").all(inspection.id)).toEqual([{ moment: "late" }]);
460
461 // Moving the date makes a fresh follow-up for the new date; a done date drafts none.
462 const to = addDays(today(), -1);
463 expect(moveDeadline(db, alice, { id: inspection.id, due: to, reason: "Needs more time" }).ok).toBe(true);
464 const moved = lates(fresh(deal.id));
465 expect(moved.map((r) => [r.due, r.sent_at])).toEqual([[to, null]]);
466 expect(declineReminder(db, alice, { ...ask, reason: "Called them" }).ok).toBe(true);
467 expect(lates(fresh(deal.id))[0]!.declined?.reason).toBe("Called them");
468 expect(markDone(db, alice, { id: inspection.id, done: true }).ok).toBe(true);
469 expect(lates(fresh(deal.id))).toEqual([]);
470 });
471
472 test("pending: an overdue follow-up stays listed while unsent; the earlier moments drop once the date passes", () => {
473 const deal = open({ contractDate: addDays(today(), -10), closingDate: addDays(today(), 30), lengths: { inspection: "8" } });
474 const inspection = due(deal, "inspection"); // due two days ago
475 const mine = (d: DealView) => drafts(d, agent).filter((r) => r.deadline_id === inspection.id);
476 const day = addDays(inspection.due, 3);
477 const late = mine(deal).find((r) => r.moment === "late")!;
478 expect(pending(late, late.on)).toBe(true);
479 expect(pending(late, day)).toBe(true);
480 expect(pending(late, addDays(late.on, -1))).toBe(false);
481 for (const r of mine(deal).filter((r) => r.moment !== "late")) expect(pending(r, addDays(inspection.due, 1))).toBe(false);
482 expect(pending(mine(deal).find((r) => r.moment === "day_of")!, inspection.due)).toBe(true);
483
484 const ask = { deadlineId: inspection.id, partyId: late.party_id, moment: "late" };
485 expect(declineReminder(db, alice, { ...ask, reason: "Spoke by phone" }).ok).toBe(true);
486 expect(pending(mine(fresh(deal.id)).find((r) => r.moment === "late")!, day)).toBe(false);
487 expect(undoDecline(db, alice, ask).ok).toBe(true);
488 expect(sendReminder(db, alice, ask).ok).toBe(true);
489 expect(pending(mine(fresh(deal.id)).find((r) => r.moment === "late")!, day)).toBe(false);
490
491 expect(markDone(db, alice, { id: inspection.id, done: true }).ok).toBe(true);
492 expect(mine(fresh(deal.id)).filter((r) => pending(r, day))).toEqual([]);
493 });
src/deals.ts +4 −4
@@ -114,9 +114,9 @@ export interface DealView extends Deal {
114114 readonly declined: readonly Declined[];
115115 }
116116
117 export type Moment = "before" | "day_of";
117 export type Moment = "before" | "day_of" | "late";
118118 export const isMoment = (v: unknown): v is Moment =>
119 v === "before" || v === "day_of";
119 v === "before" || v === "day_of" || v === "late";
120120
121121 /** Text from a person: trimmed, one line, within bounds — or undefined. */
122122 export function line(value: unknown, min: number, max: number): string | undefined {
@@ -652,7 +652,7 @@ export function sendReminder(
652652 const { dealId, found } = deadlineFor(db, who, input.deadlineId);
653653 if (!found.ok) return within(db, who, dealId, found);
654654 if (!isMoment(input.moment))
655 return within(db, who, dealId, fail("invalid", "A reminder is for three days before, or the day of."));
655 return within(db, who, dealId, fail("invalid", "A reminder is for three days before, the day of, or the day after (overdue)."));
656656 const party = Number.isInteger(input.partyId)
657657 ? db
658658 .query<Party, [number, number]>("SELECT * FROM party WHERE id = ?1 AND deal_id = ?2")
@@ -693,7 +693,7 @@ function draftOf(
693693 const { dealId, found } = deadlineFor(db, who, input.deadlineId, input.dealId);
694694 if (!found.ok) return { dealId, found };
695695 if (!isMoment(input.moment))
696 return { dealId, found: fail("invalid", "A reminder is for three days before, or the day of.") };
696 return { dealId, found: fail("invalid", "A reminder is for three days before, the day of, or the day after (overdue).") };
697697 const { deal, deadline } = found.value;
698698 const party = Number.isInteger(input.partyId)
699699 ? db.query<Party, [number, number]>("SELECT * FROM party WHERE id = ?1 AND deal_id = ?2").get(input.partyId, deal.id)
src/mcp.ts +3 −3
@@ -129,7 +129,7 @@ export const tools: readonly Tool[] = [
129129 properties: {
130130 deadline_id: { type: "integer" },
131131 party_id: { type: "integer" },
132 moment: { enum: ["before", "day_of"] },
132 moment: { enum: ["before", "day_of", "late"] },
133133 subject: { type: "string", minLength: 1, maxLength: 150 },
134134 body: { type: "string", minLength: 1, maxLength: 2000 },
135135 },
@@ -147,7 +147,7 @@ export const tools: readonly Tool[] = [
147147 properties: {
148148 deadline_id: { type: "integer" },
149149 party_id: { type: "integer" },
150 moment: { enum: ["before", "day_of"] },
150 moment: { enum: ["before", "day_of", "late"] },
151151 reason: { type: "string", minLength: 1, maxLength: 200 },
152152 },
153153 required: ["deadline_id", "party_id", "moment", "reason"],
@@ -160,7 +160,7 @@ export const tools: readonly Tool[] = [
160160 description: "Take back a decline: the reminder is a draft again, to send or decline.",
161161 inputSchema: {
162162 type: "object",
163 properties: { deadline_id: { type: "integer" }, party_id: { type: "integer" }, moment: { enum: ["before", "day_of"] } },
163 properties: { deadline_id: { type: "integer" }, party_id: { type: "integer" }, moment: { enum: ["before", "day_of", "late"] } },
164164 required: ["deadline_id", "party_id", "moment"],
165165 },
166166 run: (db, who, args) =>
src/pages/clock.ts +3 −3
@@ -10,7 +10,7 @@ import type { DealView } from "../deals.ts";
1010 import { KIND } from "../deadlines.ts";
1111 import { agent } from "../env.ts";
1212 import { escape } from "../http.ts";
13 import { drafts, unsent } from "../reminders.ts";
13 import { drafts, pending, unsent } from "../reminders.ts";
1414 import type { Who } from "../who.ts";
1515 import { thisWeek } from "../week.ts";
1616 import { layout } from "./layout.ts";
@@ -127,7 +127,7 @@ export function clock(input: {
127127 const { start, days } = span(deals, on);
128128 const today = deals.flatMap((deal) =>
129129 drafts(deal, agent)
130 .filter((r) => r.on === on || (r.on < on && unsent(r) && r.due >= on))
130 .filter((r) => pending(r, on))
131131 .map((r) => ({ r, may: canChange(who, deal) })),
132132 );
133133 const toSend = today.filter(({ r }) => unsent(r)).length;
@@ -175,7 +175,7 @@ export function clock(input: {
175175 ? `<p class="muted">Nothing goes out today.</p>`
176176 : `<ul class="drafts">${today.map(({ r, may }) => draftItem(r, on, may, "/", true)).join("")}</ul>`
177177 }
178 <p class="muted small">Each date reminds its parties three days before and the morning of. Sending is simulated: the draft is shown and marked sent.</p>
178 <p class="muted small">Each date reminds its parties three days before and the morning of, and the one who owes a date is asked for an update the morning after it slips. Sending is simulated: the draft is shown and marked sent.</p>
179179 </section>`;
180180 return layout({ body, who, path: "/", notice });
181181 }
src/pages/sheet.ts +1
@@ -114,6 +114,7 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to:
114114 ? `<p class="muted">No one to remind yet — <a href="/deals/${deal.id}#parties">add the parties</a>.</p>`
115115 : MOMENTS.map((m) => {
116116 const these = drafts.filter((r) => r.moment === m);
117 if (these.length === 0) return "";
117118 const head = `<h4>${MOMENT_LABEL[m]} <span class="muted">· ${escape(spoken(these[0]!.on))}</span></h4>`;
118119 return `${head}<ul class="drafts">${these.map((r) => draftItem(r, on, may, to)).join("")}</ul>`;
119120 }).join("");
src/reminders.ts +34 −13
@@ -1,9 +1,10 @@
11 /**
22 * Reminders, drafted. Every open date of a deal reminds each party it
3 * concerns twice: three days before, and the morning of. A draft is plain
4 * data — who, when, the words — computed from a deal; nothing is sent
5 * anywhere. `sendReminder` (`deals.ts`) records that the agent sent one, with
6 * the words approved; a sent draft reads back those words.
3 * concerns three days before and the morning of; a date that slips past due
4 * while still open gets a third, the morning after, to the party who owes it
5 * alone. A draft is plain data — who, when, the words — computed from a deal;
6 * nothing is sent anywhere. `sendReminder` (`deals.ts`) records that the agent
7 * sent one, with the words approved; a sent draft reads back those words.
78 */
89
910 import { addDays, spoken } from "./dates.ts";
@@ -36,17 +37,23 @@ export interface Draft {
3637 readonly declined: { readonly reason: string; readonly by_name: string } | null;
3738 }
3839
39 export const MOMENTS: readonly Moment[] = ["before", "day_of"];
40 export const MOMENTS: readonly Moment[] = ["before", "day_of", "late"];
4041 export const MOMENT_LABEL: Readonly<Record<Moment, string>> = {
4142 before: "3 days before",
4243 day_of: "Morning of",
44 late: "Overdue follow-up",
4345 };
44 export const sendOn = (due: string, moment: Moment): string =>
45 moment === "before" ? addDays(due, -3) : due;
46 const OFFSET: Readonly<Record<Moment, number>> = { before: -3, day_of: 0, late: 1 };
47 export const sendOn = (due: string, moment: Moment): string => addDays(due, OFFSET[moment]);
4648
47 /** The parties a date concerns: whoever owes it, then whoever its kind tells. */
48 export function recipients(deal: DealView, deadline: DeadlineView): Party[] {
49 const roles = new Set<PartyRole>([deadline.owes, ...KIND[deadline.kind].notify]);
49 /**
50 * The parties a moment tells: whoever owes the date, then whoever its kind
51 * notifies; an overdue follow-up goes to whoever owes it alone.
52 */
53 export function recipients(deal: DealView, deadline: DeadlineView, moment: Moment = "day_of"): Party[] {
54 const roles = new Set<PartyRole>(
55 moment === "late" ? [deadline.owes] : [deadline.owes, ...KIND[deadline.kind].notify],
56 );
5057 return deal.parties.filter((p) => roles.has(p.role));
5158 }
5259
@@ -59,10 +66,16 @@ function words(
5966 moment: Moment,
6067 agent: Agent,
6168 ): { subject: string; body: string } {
62 const when = moment === "before" ? `in three days, on ${spoken(deadline.due)}` : `today, ${spoken(deadline.due)}`;
6369 const owner = deal.parties.find((p) => p.role === deadline.owes);
64 const yours = party.role === deadline.owes;
6570 const owed = deadline.what === "" ? "" : `${deadline.what}. `;
71 if (moment === "late") {
72 return {
73 subject: `${deadline.label} — ${deal.address} — overdue`,
74 body: `Hi ${first(party.name)}, the ${deadline.label.toLowerCase()} for ${deal.address} was due ${spoken(deadline.due)} and has passed without being marked done. ${owed}Could you send me an update today on where it stands and when it will be done?\n\n${agent.name}, ${agent.brokerage}`,
75 };
76 }
77 const when = moment === "before" ? `in three days, on ${spoken(deadline.due)}` : `today, ${spoken(deadline.due)}`;
78 const yours = party.role === deadline.owes;
6679 const ask = yours
6780 ? "This one is yours — please let me know right away if anything could hold it up."
6881 : `${owner === undefined ? PARTY_LABEL[deadline.owes] : owner.name} (${PARTY_LABEL[deadline.owes].toLowerCase()}) is on it; nothing is needed from you unless you hear otherwise.`;
@@ -83,7 +96,7 @@ export function drafts(deal: DealView, agent: Agent): Draft[] {
8396 /** The reminders one date has, sent or not. */
8497 export function draftsFor(deal: DealView, deadline: DeadlineView, agent: Agent): Draft[] {
8598 return MOMENTS.flatMap((moment) =>
86 recipients(deal, deadline).map((party) => {
99 recipients(deal, deadline, moment).map((party) => {
87100 const sent = deal.sent.find(
88101 (s) =>
89102 s.deadline_id === deadline.id &&
@@ -127,3 +140,11 @@ export const unsent = (d: Draft): boolean => d.sent_at === null && d.declined ==
127140 /** What goes out on `day` and has not gone yet: `POST /tick`'s answer. */
128141 export const dueOn = (deals: readonly DealView[], day: string, agent: Agent): Draft[] =>
129142 deals.flatMap((deal) => drafts(deal, agent)).filter((d) => d.on === day && d.sent_at === null && d.declined === null);
143
144 /**
145 * Waiting on `day`: goes out that morning, or was missed and still matters —
146 * a before/day-of draft until its date passes, an overdue follow-up for as
147 * long as the date stays open.
148 */
149 export const pending = (d: Draft, day: string): boolean =>
150 d.on === day || (d.on < day && unsent(d) && (d.due >= day || d.moment === "late"));
src/routes.ts +5 −5
@@ -159,7 +159,7 @@ export const DEAL: Schema = {
159159 id: { type: "integer" },
160160 deadline_id: { type: "integer" },
161161 party_id: { type: "integer" },
162 moment: { enum: ["before", "day_of"] },
162 moment: { enum: ["before", "day_of", "late"] },
163163 due: DATE,
164164 reason: { type: "string", description: "Why the agent chose not to send it." },
165165 by_name: { type: "string" },
@@ -180,7 +180,7 @@ export const DEAL: Schema = {
180180 label: { type: "string", description: "The date it was about, as named when sent." },
181181 party_name: { type: "string" },
182182 party_role: { type: "string", description: "The party's role when sent; empty on a reminder sent before roles were kept." },
183 moment: { enum: ["before", "day_of"] },
183 moment: { enum: ["before", "day_of", "late"] },
184184 due: DATE,
185185 by_name: { type: "string" },
186186 sent_at: { type: "string" },
@@ -221,7 +221,7 @@ export const DRAFT: Schema = {
221221 party_name: { type: "string" },
222222 party_role: ROLE,
223223 contact: { type: "string" },
224 moment: { enum: ["before", "day_of"] },
224 moment: { enum: ["before", "day_of", "late"] },
225225 on: DATE,
226226 subject: { type: "string" },
227227 body: { type: "string" },
@@ -644,7 +644,7 @@ export const routes: readonly Route[] = [
644644 "Choose not to send a reminder, with a reason (1 to 200 characters). It is kept as a record, no longer counts as to send, and leaves /tick.",
645645 body: {
646646 type: "object",
647 properties: { deadline_id: { type: "integer" }, party_id: { type: "integer" }, moment: { enum: ["before", "day_of"] }, reason: { type: "string", minLength: 1, maxLength: 200 } },
647 properties: { deadline_id: { type: "integer" }, party_id: { type: "integer" }, moment: { enum: ["before", "day_of", "late"] }, reason: { type: "string", minLength: 1, maxLength: 200 } },
648648 required: ["deadline_id", "party_id", "moment", "reason"],
649649 },
650650 answer: { type: "object", properties: { id: { type: "integer" }, reason: { type: "string" }, by_name: { type: "string" } }, required: ["id", "reason"] },
@@ -666,7 +666,7 @@ export const routes: readonly Route[] = [
666666 summary: "Take back a decline: the reminder is a draft again.",
667667 body: {
668668 type: "object",
669 properties: { deadline_id: { type: "integer" }, party_id: { type: "integer" }, moment: { enum: ["before", "day_of"] } },
669 properties: { deadline_id: { type: "integer" }, party_id: { type: "integer" }, moment: { enum: ["before", "day_of", "late"] } },
670670 required: ["deadline_id", "party_id", "moment"],
671671 },
672672 answer: { type: "object", properties: { id: { type: "integer" } }, required: ["id"] },
src/sample.test.ts +17
@@ -1,4 +1,11 @@
11 import { expect, test } from "bun:test";
2 import { mkdtempSync } from "node:fs";
3 import { tmpdir } from "node:os";
4 import { join } from "node:path";
5 import { openDb } from "./db.ts";
6 import { listDeals } from "./deals.ts";
7 import { drafts, unsent } from "./reminders.ts";
8 import type { Who } from "./who.ts";
29 import { isUntouched, shiftSample, type SampleDates } from "./sample.ts";
310
411 const dates: SampleDates = {
@@ -41,3 +48,13 @@ test("a sample a person changed is not untouched", () => {
4148 expect(isUntouched({ ...state, doneAts: ["2026-09-30T17:00:00.000Z", "2026-10-02T08:00:00.000Z", null] }, "2026-10-01")).toBe(false);
4249 expect(isUntouched({ ...state, address: "Mine" }, "2026-10-01")).toBe(false);
4350 });
51
52 test("the sample deals hold an overdue date with its follow-up waiting", () => {
53 const db = openDb(mkdtempSync(join(tmpdir(), "app-sample-late-")));
54 const alice: Who = { role: "user", id: "u1", name: "alice" };
55 const listed = listDeals(db, alice);
56 if (!listed.ok) throw new Error(listed.message);
57 const agent = { name: "Dana", brokerage: "HP" };
58 const late = listed.value.flatMap((d) => drafts(d, agent)).filter((r) => r.moment === "late" && unsent(r));
59 expect(late.length).toBeGreaterThan(0);
60 });
src/terminal.test.ts +22
@@ -347,3 +347,25 @@ test("s on a deal lists what was sent, newest first, with the words; b comes bac
347347 expect(lines(guest).join("\n")).not.toContain("First <b>words</b>");
348348 expect(lines(guest).join("\n")).not.toContain("Messages —");
349349 });
350
351 test("r lists an overdue follow-up as late, as the clock page does, until it is sent", () => {
352 const slipped = createDeal(db, alice, {
353 address: "5 Late Ln",
354 buyer: "Lena Buyer",
355 seller: "Sid Seller",
356 contractDate: addDays(today(), -20),
357 closingDate: addDays(today(), 30),
358 });
359 if (!slipped.ok) throw new Error(slipped.message);
360 const missed = addDeadline(db, alice, { dealId: slipped.value.id, label: "Appraisal back", due: addDays(today(), -3), owes: "buyer" });
361 if (!missed.ok) throw new Error(missed.message);
362 const t = terminal(db, alice, context);
363 t.press("r");
364 const row = () => lines(t).find((l) => l.includes("Lena Buyer") && l.includes("Appraisal back") && l.includes("overdue follow-up"));
365 expect(row()).toContain("late");
366 expect(lines(t).filter((l) => l.includes("Sid Seller") && l.includes("Appraisal back") && l.includes("overdue follow-up"))).toEqual([]);
367 expect(sendReminder(db, alice, { deadlineId: missed.value.id, partyId: slipped.value.parties.find((p) => p.name === "Lena Buyer")!.id, moment: "late" }).ok).toBe(true);
368 const again = terminal(db, alice, context);
369 again.press("r");
370 expect(lines(again).some((l) => l.includes("Appraisal back") && l.includes("overdue follow-up"))).toBe(false);
371 });
src/terminal.ts +2 −2
@@ -45,7 +45,7 @@ import {
4545 type DeadlineView,
4646 } from "./deals.ts";
4747 import { PARTY_LABEL, PARTY_ROLES, type PartyRole } from "./deadlines.ts";
48 import { drafts, MOMENT_LABEL, unsent, type Agent, type Draft } from "./reminders.ts";
48 import { drafts, MOMENT_LABEL, pending, unsent, type Agent, type Draft } from "./reminders.ts";
4949 import type { Result } from "./result.ts";
5050 import type { Who } from "./who.ts";
5151 import { owner, thisWeek } from "./week.ts";
@@ -121,7 +121,7 @@ export function terminal(
121121 const day = on();
122122 return deals().flatMap((deal) =>
123123 drafts(deal, context.agent)
124 .filter((r) => r.on === day || (r.on < day && unsent(r) && r.due >= day))
124 .filter((r) => pending(r, day))
125125 .map((draft) => ({ deal, draft })),
126126 );
127127 };

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs