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

A reminder held until tomorrow can be brought back to today with one tap, from the deal's page or the review page #111

Merged opened this

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

Merged

mason/deal-clock:mason/109-a-reminder-held-until-tomorrow-can-be-br → main 3 commits fork

  • Merged. mason/109-a-reminder-held-until-tomorrow-can-be-br was merged into main as 03d78a2.

Review

Sign in to review this change.
14 files changed +365 −11
README.md +1 −1
@@ -78,7 +78,7 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture
7878 Decided against a message? Beside Send, **Don't send** asks why (up to 200
7979 characters). The reminder stops counting as "to send" and reads "Not sent:
8080 <reason> · <who>"; the reason is kept, and **Undo** makes it a draft again.
81 Not ready to approve one? **Tomorrow** holds it: it leaves today's list and the count, and returns at the top tomorrow as "Held from <weekday>" with your edited words (hold it again to push it another day). In the terminal, press h on the reminders list.
81 Not ready to approve one? **Tomorrow** holds it: it leaves today's list and the count, and returns at the top tomorrow as "Held from <weekday>" with your edited words (hold it again to push it another day). Changed your mind? **Bring back** on the deal's Messages list returns it to today at once; in the terminal, press H on the reminders list to see the held ones and B to bring the one under the cursor back. In the terminal, press h on the reminders list.
8282 To keep a client informed about the whole deal, a deal's page also has a
8383 **Status update** card for each buyer and seller with an email or phone: a
8484 draft of what is done, what is next and who owes it, and when it closes,
contract/openapi.json +80
@@ -1554,6 +1554,86 @@
15541554 "verb": "update",
15551555 "least": "user"
15561556 }
1557 },
1558 "delete": {
1559 "summary": "Bring a held reminder back to today: the hold is deleted and the reminder returns to today's list and /tick. Refused as a conflict when it is not held, or was already sent or declined.",
1560 "operationId": "deleteApiDealsIdRemindersHold",
1561 "parameters": [
1562 {
1563 "name": "id",
1564 "in": "path",
1565 "required": true,
1566 "schema": {
1567 "type": "integer"
1568 }
1569 }
1570 ],
1571 "requestBody": {
1572 "required": true,
1573 "content": {
1574 "application/json": {
1575 "schema": {
1576 "type": "object",
1577 "properties": {
1578 "deadline_id": {
1579 "type": "integer"
1580 },
1581 "party_id": {
1582 "type": "integer"
1583 },
1584 "moment": {
1585 "enum": [
1586 "before",
1587 "day_of",
1588 "late",
1589 "moved"
1590 ]
1591 }
1592 },
1593 "required": [
1594 "deadline_id",
1595 "party_id",
1596 "moment"
1597 ]
1598 }
1599 }
1600 }
1601 },
1602 "responses": {
1603 "200": {
1604 "description": "Bring a held reminder back to today: the hold is deleted and the reminder returns to today's list and /tick. Refused as a conflict when it is not held, or was already sent or declined.",
1605 "content": {
1606 "application/json": {
1607 "schema": {
1608 "type": "object",
1609 "properties": {
1610 "id": {
1611 "type": "integer"
1612 }
1613 },
1614 "required": [
1615 "id"
1616 ]
1617 }
1618 }
1619 }
1620 },
1621 "default": {
1622 "description": "{ error, message }: why not",
1623 "content": {
1624 "application/json": {
1625 "schema": {
1626 "$ref": "#/components/schemas/Error"
1627 }
1628 }
1629 }
1630 }
1631 },
1632 "x-contract": {
1633 "resource": "deal",
1634 "verb": "update",
1635 "least": "user"
1636 }
15571637 }
15581638 },
15591639 "/api/deals/{id}/reminders/undo": {
docs/TECHNICAL.md +2
@@ -120,6 +120,8 @@ returns at the top as "Held from <weekday>", and holding again pushes `until` on
120120 day. Posts: `/reminders/hold`, `/reminders/today/hold`, `POST /api/deals/:id/reminders/hold`;
121121 MCP `hold_reminder`; in the terminal, `h` on the reminders list. A reminder can be held only from its send morning on. Audited as `reminder.hold:<until>`. Same `deal` update cell as Send.
122122
123 Bringing one back: in the terminal, `H` on the reminders list shows the held ones and `B` brings one back; `POST /reminders/release` (the Bring back button on the deal's Messages list), `DELETE /api/deals/:id/reminders/hold`, MCP `release_reminder`. It deletes the hold; a reminder that is not held, sent or declined is a 409. Audited as `reminder.release`. Same `deal` update cell.
124
123125 `GET /deals/:id/sheets` is an HTML fragment: every date's sheet for one deal. The clock carries
124126 no sheets (they were most of its size); `sheets.js` fetches a deal's the first time one of its dates is tapped,
125127 and without script the date is a link to `/deals/:id#sheet-N`; the deal page has its sheets inline,
src/activity.ts +1
@@ -17,6 +17,7 @@ const WORDS: Readonly<Record<string, string>> = {
1717 "reminder.send": "sent a reminder",
1818 "reminder.decline": "declined a reminder",
1919 "reminder.hold": "held a reminder",
20 "reminder.release": "brought back a held reminder",
2021 "reminder.undo": "undid a declined reminder",
2122 "date.move": "moved a date",
2223 "date.done": "marked a date done",
src/audit.ts +1 −1
@@ -42,7 +42,7 @@ export interface Attempt {
4242 }
4343
4444 /** The changes that are a message's life: sent, declined, held, undone. The Activity page's `only=messages`. */
45 export const MESSAGE_WHATS = ["reminder.send", "reminder.decline", "reminder.undo"] as const;
45 export const MESSAGE_WHATS = ["reminder.send", "reminder.decline", "reminder.release", "reminder.undo"] as const;
4646 /** A hold is audited as `reminder.hold:<the day it comes back>`. */
4747 export const HOLD_WHAT = "reminder.hold";
4848
src/deals.ts +24
@@ -1189,6 +1189,30 @@ export function holdReminder(
11891189 return within(db, who, `reminder.hold:${until}`, dealId, ok(held));
11901190 }
11911191
1192 /**
1193 * Bring a held reminder back to today: the hold is deleted, so the reminder
1194 * is in today's list and the count at once, without its "Held from" label.
1195 */
1196 export function releaseReminder(
1197 db: Database,
1198 who: Who,
1199 input: { deadlineId: number; dealId?: number; partyId: number; moment: unknown; agent?: Agent },
1200 ): Result<{ id: number }> {
1201 const { dealId, found } = draftOf(db, who, input);
1202 const what = "reminder.release";
1203 if (!found.ok) return within(db, who, what, dealId, found);
1204 const { draft } = found.value;
1205 if (draft.sent_at !== null) return within(db, who, what, dealId, fail("conflict", "This reminder was already sent, so it is not held."));
1206 if (draft.declined !== null) return within(db, who, what, dealId, fail("conflict", "This reminder was declined, so it is not held."));
1207 const gone = db
1208 .query<{ id: number }, [number, number, string, string, number]>(
1209 "DELETE FROM reminder_hold WHERE deadline_id = ?1 AND party_id = ?2 AND moment = ?3 AND due = ?4 AND move_id = ?5 RETURNING id",
1210 )
1211 .get(draft.deadline_id, draft.party_id, draft.moment, draft.due, draft.move_id);
1212 if (gone === null) return within(db, who, what, dealId, fail("conflict", "This reminder is not held."));
1213 return within(db, who, what, dealId, ok({ id: gone.id }));
1214 }
1215
11921216 /** Take back a decline: the reminder is a draft again. */
11931217 export function undoDecline(
11941218 db: Database,
src/mcp.ts +12
@@ -35,6 +35,7 @@ import {
3535 setOwes,
3636 declineReminder,
3737 holdReminder,
38 releaseReminder,
3839 undoDecline,
3940 } from "./deals.ts";
4041 import { LENGTH_MAX, standard, title } from "./env.ts";
@@ -283,6 +284,17 @@ export const tools: readonly Tool[] = [
283284 run: (db, who, args) =>
284285 holdReminder(db, who, { deadlineId: Number(args.deadline_id), partyId: Number(args.party_id), moment: args.moment }),
285286 },
287 {
288 name: "release_reminder",
289 description: "Bring a held reminder back to today, for when the agent is ready to send it after all: the hold is deleted and it returns to reminders_today. Refused when it is not held, or was already sent or declined.",
290 inputSchema: {
291 type: "object",
292 properties: { deadline_id: { type: "integer" }, party_id: { type: "integer" }, moment: { enum: ["before", "day_of", "late", "moved"] } },
293 required: ["deadline_id", "party_id", "moment"],
294 },
295 run: (db, who, args) =>
296 releaseReminder(db, who, { deadlineId: Number(args.deadline_id), partyId: Number(args.party_id), moment: args.moment }),
297 },
286298 {
287299 name: "undo_decline_reminder",
288300 description: "Take back a decline: the reminder is a draft again, to send or decline.",
src/pages/deal.ts +4 −4
@@ -16,7 +16,7 @@ import { partyContact } from "./contact.ts";
1616 import { confirmRemove } from "./confirm.ts";
1717 import { layout } from "./layout.ts";
1818 import { progressLine } from "./progress.ts";
19 import { badge, conflictLines, nonBusinessLine, rollForm, draftItem, dueLine, outboxLine, owedBy, sheet, sheetId } from "./sheet.ts";
19 import { badge, conflictLines, nonBusinessLine, rollForm, draftItem, dueLine, outboxLine, owedBy, releaseForm, sheet, sheetId } from "./sheet.ts";
2020
2121 const roleOptions = (selected?: string): string =>
2222 PARTY_ROLES.map(
@@ -64,12 +64,12 @@ function statusCard(deal: DealView, agent: Agent, on: string, may: boolean, to:
6464 }
6565
6666 /** The record of what went out: each sent reminder with the words approved, newest first. */
67 function messages(deal: DealView, may: boolean, agent: Agent): string {
67 function messages(deal: DealView, may: boolean, agent: Agent, to: string): string {
6868 const holding = drafts(deal, agent).flatMap((d) => (d.held === null ? [] : [{ d, held: d.held }]));
6969 const waiting = holding.length === 0
7070 ? ""
7171 : `<ul class="drafts">${holding
72 .map(({ d, held }) => `<li class="draft"><span><b>${escape(d.party_name)}</b> <span class="muted">· ${escape(d.label)}, ${escape(short(d.due))} · ${escape(sentLabel(d.moment))}</span></span><span class="state">Held until ${escape(spoken(held.until))} by ${escape(held.by_name || "someone")}</span></li>`)
72 .map(({ d, held }) => `<li class="draft"><span><b>${escape(d.party_name)}</b> <span class="muted">· ${escape(d.label)}, ${escape(short(d.due))} · ${escape(sentLabel(d.moment))}</span></span><span class="state">Held until ${escape(spoken(held.until))} by ${escape(held.by_name || "someone")}</span>${may ? releaseForm(d, to) : ""}</li>`)
7373 .join("")}</ul>`;
7474 if (deal.sent.length === 0) return `${waiting}<p class="muted">Nothing sent yet</p>`;
7575 const live = new Set(deal.deadlines.map((d) => d.id));
@@ -184,7 +184,7 @@ export function dealPage(input: {
184184 ${statusCard(deal, agent ?? defaults, on, may, path)}
185185 <section class="card" id="messages">
186186 <h2>Messages</h2>
187 ${messages(deal, may, agent ?? defaults)}
187 ${messages(deal, may, agent ?? defaults, path)}
188188 </section>
189189 ${deal.deadlines.map((d) => sheet(deal, d, who, on, path, agent)).join("")}
190190 </div>
src/pages/sheet.ts +6
@@ -118,6 +118,12 @@ export const holdForm = (draft: Draft, to: string, action = "/reminders/hold", k
118118 <button class="button button-quiet">Tomorrow</button>
119119 </form>`;
120120
121 /** A held reminder, for whoever may change the deal: the way back to today. A plain POST. */
122 export const releaseForm = (draft: Draft, to: string): string =>
123 `<form method="post" action="/reminders/release">${hidden({ deadline: draft.deadline_id, party: draft.party_id, moment: draft.moment, to })}
124 <button class="button button-quiet">Bring back</button>
125 </form>`;
126
121127 /** A declined reminder: the reason on record, and — for whoever may change the deal — the way back. */
122128 const undoForm = (draft: Draft, to: string): string =>
123129 `<form method="post" action="/reminders/undo">${hidden({ deadline: draft.deadline_id, party: draft.party_id, moment: draft.moment, to })}
src/release.test.ts added +141
@@ -0,0 +1,141 @@
1 /** Bringing a held reminder back to today: the hold is deleted, and the reminder is a draft of today again. */
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 { listAudit } from "./actions.ts";
7 import { wording } from "./activity.ts";
8 import { addDays, today } from "./dates.ts";
9 import { openDb } from "./db.ts";
10 import { createDeal, getDeal, holdReminder, releaseReminder, sendReminder, declineReminder, type DealView } from "./deals.ts";
11 import { todaysDrafts, waitingCount } from "./reminders.ts";
12 import { forgetRationing } from "./security.ts";
13 import { serve } from "./server.ts";
14 import type { Who } from "./who.ts";
15 import { sign } from "./who.ts";
16
17 const db = openDb(mkdtempSync(join(tmpdir(), "app-release-")));
18 const alice: Who = { role: "user", id: "u1", name: "alice" };
19 const admin: Who = { role: "admin", id: "a1", name: "root" };
20 const anon: Who = { role: "anon" };
21 const agent = { name: "Dana Whitfield", brokerage: "Harbor & Pine Realty", phone: "(555) 010-0142", email: "[email protected]" };
22
23 const now = today();
24 const made = createDeal(db, alice, { openAnyway: true, address: "9 Release Ln", buyer: "Ann Buyer", seller: "Sam Seller", contractDate: addDays(now, -5), closingDate: addDays(now, 40), lengths: { inspection: "8" } });
25 if (!made.ok) throw new Error(made.message);
26 const deal: DealView = made.value;
27 const fresh = (): DealView => {
28 const got = getDeal(db, alice, { id: deal.id });
29 if (!got.ok) throw new Error(got.message);
30 return got.value;
31 };
32 const inspection = deal.deadlines.find((d) => d.kind === "inspection")!;
33 const mine = () => todaysDrafts([fresh()], now, agent).filter((d) => d.deadline_id === inspection.id && d.moment === "before");
34 const first = mine()[0]!;
35 const ask = { dealId: deal.id, deadlineId: first.deadline_id, partyId: first.party_id, moment: first.moment };
36
37 test("hold, then bring back: the reminder is in today's list and the count, unlabelled", () => {
38 const before = waitingCount([fresh()], now, agent);
39 expect(holdReminder(db, alice, ask).ok).toBe(true);
40 expect(mine().some((d) => d.party_id === first.party_id)).toBe(false);
41 expect(waitingCount([fresh()], now, agent)).toBe(before - 1);
42 const back = releaseReminder(db, alice, ask);
43 expect(back.ok).toBe(true);
44 const again = mine().find((d) => d.party_id === first.party_id)!;
45 expect(again.held).toBeNull();
46 expect(waitingCount([fresh()], now, agent)).toBe(before);
47 });
48
49 test("a reminder that is not held, or was sent or declined, is a conflict that says why", () => {
50 const notHeld = releaseReminder(db, alice, ask);
51 expect(!notHeld.ok && notHeld.error).toBe("conflict");
52 expect(!notHeld.ok && notHeld.message).toBe("This reminder is not held.");
53 const other = mine().find((d) => d.party_id !== first.party_id)!;
54 const otherAsk = { dealId: deal.id, deadlineId: other.deadline_id, partyId: other.party_id, moment: other.moment };
55 expect(declineReminder(db, alice, { ...otherAsk, reason: "Told by phone" }).ok).toBe(true);
56 const declined = releaseReminder(db, alice, otherAsk);
57 expect(!declined.ok && declined.error).toBe("conflict");
58 expect(sendReminder(db, alice, ask).ok).toBe(true);
59 const sent = releaseReminder(db, alice, ask);
60 expect(!sent.ok && sent.error).toBe("conflict");
61 expect(!sent.ok && sent.message).toContain("already sent");
62 });
63
64 test("anonymous is asked to sign in, and Activity words it as brought back", () => {
65 const refused = releaseReminder(db, anon, ask);
66 expect(!refused.ok && refused.error).toBe("signin_required");
67 const rows = listAudit(db, admin, {});
68 expect(rows.ok).toBe(true);
69 const row = rows.ok ? rows.value.find((r) => r.what === "reminder.release") : undefined;
70 expect(row).toBeDefined();
71 expect(wording(row!)).toBe("brought back a held reminder");
72 });
73
74 // ---- through the door ----
75
76 const KEY = "a-key-only-the-forge-holds";
77 const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-release-web-")), identityKey: KEY });
78 const base = `http://${server.hostname}:${server.port}`;
79 afterAll(() => server.stop(true));
80 beforeEach(forgetRationing);
81 const identity = `u1|alice|user|${Date.now() + 600_000}`;
82 const signed = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) };
83 const post = (path: string, fields: Record<string, string>, headers: Record<string, string> = signed) =>
84 fetch(base + path, { method: "POST", body: new URLSearchParams(fields), headers: { ...headers, "content-type": "application/x-www-form-urlencoded" }, redirect: "manual" });
85
86 test("the deal page offers Bring back as a form; it posts, and another origin and an anonymous visitor are refused", async () => {
87 const res = await fetch(`${base}/api/deals`, {
88 method: "POST",
89 headers: { ...signed, "content-type": "application/json" },
90 body: JSON.stringify({ address: "9 Web Ln", buyer: "Ann Buyer", seller: "Sam Seller", contract_date: addDays(now, -7), closing_date: addDays(now, 40), open_anyway: true }),
91 });
92 expect(res.status).toBe(201);
93 const web = (await res.json()) as { id: number; deadlines: { id: number; kind: string }[]; parties: { id: number; role: string }[] };
94 const keys = { deadline: String(web.deadlines.find((d) => d.kind === "inspection")!.id), party: String(web.parties[0]!.id), moment: "before", to: `/deals/${web.id}` };
95 expect((await post("/reminders/hold", keys)).status).toBe(303);
96 const page = await (await fetch(`${base}/deals/${web.id}`, { headers: signed })).text();
97 expect(page).toContain('action="/reminders/release"');
98 expect(page).toContain(">Bring back<");
99 expect((await post("/reminders/release", keys, { ...signed, origin: "https://evil.example" })).status).toBeGreaterThanOrEqual(400);
100 expect((await post("/reminders/release", keys, {})).status).not.toBe(200);
101 expect(await (await fetch(`${base}/deals/${web.id}`, { headers: signed })).text()).toContain(">Bring back<");
102 expect((await post("/reminders/release", keys)).status).toBe(303);
103 const after = await (await fetch(`${base}/deals/${web.id}`, { headers: signed })).text();
104 expect(after).not.toContain('action="/reminders/release"');
105 const again = await post("/reminders/release", keys);
106 expect(decodeURIComponent(again.headers.get("set-cookie") ?? "")).toContain("This reminder is not held.");
107 const api = await fetch(`${base}/api/deals/${web.id}/reminders/hold`, {
108 method: "DELETE",
109 headers: { ...signed, "content-type": "application/json" },
110 body: JSON.stringify({ deadline_id: Number(keys.deadline), party_id: Number(keys.party), moment: "before" }),
111 });
112 expect(api.status).toBe(409);
113 expect(await (await fetch(`${base}/openapi.json`, { headers: signed })).text()).toContain("/api/deals/{id}/reminders/hold");
114 });
115
116 test("release_reminder over MCP: brought back after a hold, an error when it is not held, refused for anonymous", async () => {
117 const res = await fetch(`${base}/api/deals`, {
118 method: "POST",
119 headers: { ...signed, "content-type": "application/json" },
120 body: JSON.stringify({ address: "9 Mcp Ln", buyer: "Ann Buyer", seller: "Sam Seller", contract_date: addDays(now, -7), closing_date: addDays(now, 40), open_anyway: true }),
121 });
122 const web = (await res.json()) as { id: number; deadlines: { id: number; kind: string }[]; parties: { id: number }[] };
123 const args = { deadline_id: web.deadlines.find((d) => d.kind === "inspection")!.id, party_id: web.parties[0]!.id, moment: "before" };
124 const call = async (name: string, who: Record<string, string>) =>
125 (
126 await (
127 await fetch(`${base}/mcp`, {
128 method: "POST",
129 headers: { ...who, "content-type": "application/json" },
130 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } }),
131 })
132 ).json()
133 ).result as { isError?: boolean; content: { text: string }[] };
134 expect((await call("hold_reminder", signed)).isError).toBeUndefined();
135 expect((await call("release_reminder", {})).isError).toBe(true);
136 const back = await call("release_reminder", signed);
137 expect(back.isError).toBeUndefined();
138 const again = await call("release_reminder", signed);
139 expect(again.isError).toBe(true);
140 expect(again.content[0]!.text).toContain("This reminder is not held.");
141 });
src/routes.ts +29
@@ -70,6 +70,7 @@ import {
7070 setOwes,
7171 declineReminder,
7272 holdReminder,
73 releaseReminder,
7374 undoDecline,
7475 updateDeal,
7576 type NewDeal,
@@ -1100,6 +1101,15 @@ export const routes: readonly Route[] = [
11001101 path: "/reminders/today/hold",
11011102 handle: (c) => reviewed(c, (f) => holdReminder(c.db, c.who, { deadlineId: Number(f.deadline), partyId: Number(f.party), moment: f.moment }), HELD),
11021103 },
1104 {
1105 method: "POST",
1106 path: "/reminders/release",
1107 handle: async (c) => {
1108 const f = await form(c);
1109 if (f instanceof Response) return f;
1110 return done(releaseReminder(c.db, c.who, { deadlineId: Number(f.deadline), partyId: Number(f.party), moment: f.moment }), backTo(f.to), "Brought back to today.");
1111 },
1112 },
11031113 {
11041114 method: "POST",
11051115 path: "/reminders/undo",
@@ -1325,6 +1335,25 @@ export const routes: readonly Route[] = [
13251335 status: 201,
13261336 },
13271337 },
1338 {
1339 method: "DELETE",
1340 path: "/api/deals/:id/reminders/hold",
1341 handle: async (c) => {
1342 const body = await readJson(c.request);
1343 if (body === undefined) return json({ error: "too_large" }, 413);
1344 const f = fields(body);
1345 return answer(releaseReminder(c.db, c.who, { dealId: Number(c.params.id), deadlineId: Number(f.deadline_id), partyId: Number(f.party_id), moment: f.moment }));
1346 },
1347 api: {
1348 summary: "Bring a held reminder back to today: the hold is deleted and the reminder returns to today's list and /tick. Refused as a conflict when it is not held, or was already sent or declined.",
1349 body: {
1350 type: "object",
1351 properties: { deadline_id: { type: "integer" }, party_id: { type: "integer" }, moment: { enum: ["before", "day_of", "late", "moved"] } },
1352 required: ["deadline_id", "party_id", "moment"],
1353 },
1354 answer: { type: "object", properties: { id: { type: "integer" } }, required: ["id"] },
1355 },
1356 },
13281357 {
13291358 method: "POST",
13301359 path: "/api/deals/:id/reminders/undo",
src/server.test.ts +1
@@ -190,6 +190,7 @@ test("the MCP server lists the tools and calls them as the caller", async () =>
190190 "send_status_update",
191191 "decline_reminder",
192192 "hold_reminder",
193 "release_reminder",
193194 "undo_decline_reminder",
194195 "open_deal",
195196 "add_date",
src/terminal.test.ts +24
@@ -285,6 +285,30 @@ test("h holds a reminder until tomorrow: it leaves the list, is written, and ano
285285 expect(holds()).toBe(before + 1);
286286 });
287287
288 test("H lists the held reminders and B brings one back to today; anon cannot", () => {
289 const t = terminal(db, alice, context);
290 t.press("r");
291 const row = under(t).replace(/^▸\s+\S+(\s\S+)?\s+(?=[A-Z])/, "");
292 t.press("h");
293 expect(lines(t).join("\n")).not.toContain(row);
294 t.press("H");
295 expect(lines(t).join("\n")).toContain("Held reminders");
296 expect(lines(t).join("\n")).toContain(row);
297 for (let i = 0; i < 50 && !under(t).includes(row); i++) t.press("j");
298 const guest = terminal(db, { role: "anon" }, context);
299 guest.press("r");
300 guest.press("H");
301 const holds = () => db.query<{ n: number }, []>("SELECT count(*) AS n FROM reminder_hold").get()!.n;
302 const held = holds();
303 guest.press("B");
304 expect(holds()).toBe(held);
305 t.press("B");
306 expect(lines(t).join("\n")).toContain("back in today's list");
307 expect(holds()).toBe(held - 1);
308 t.press("H");
309 expect(lines(t).join("\n")).toContain(row);
310 });
311
288312 test("a closed deal's dates leave the date list and reminders, it is listed under Closed, and u reopens it", () => {
289313 // The inspection ends in three days, so its "3 days before" reminder goes out today.
290314 const other = createDeal(db, alice, {
src/terminal.ts +39 −5
@@ -5,7 +5,7 @@
55 *
66 * dates every open date of every deal, soonest first (h shows done ones)
77 * week the open dates overdue or due in the next seven days, by day
8 * reminders what goes out today; enter reads a draft, e edits its words, s sends it
8 * reminders what goes out today; enter reads a draft, e edits its words, s sends it; h holds it until tomorrow, H lists the held ones and B brings one back
99 * people each person on the deals with every open date they owe (P)
1010 * timeline a deal's dates as a client would get them (t on a deal)
1111 * activity who approved, declined or changed what, newest first (L, admins); m only messages, o older, y newer
@@ -53,6 +53,7 @@ import {
5353 statusUpdates,
5454 declineReminder,
5555 holdReminder,
56 releaseReminder,
5657 undoDecline,
5758 REASON_MAX,
5859 ROLL_REASON,
@@ -116,6 +117,8 @@ export function terminal(
116117 let cursor = 0;
117118 let dealId: number | undefined;
118119 let showDone = false;
120 /** Reminders: the ones held for a later morning, not today's. */
121 let showHeld = false;
119122 let reading: number | undefined;
120123 /** Words typed with `e` and not yet sent, by reminder; `s` sends them. */
121124 const edits = new Map<string, { subject: string; body: string }>();
@@ -152,6 +155,12 @@ export function terminal(
152155 /** Today's reminders: what goes out today, and what should have and has not, for dates still ahead. */
153156 const reminderRows = (): { deal: DealView; draft: Draft }[] => {
154157 const day = on();
158 if (showHeld)
159 return deals().flatMap((deal) =>
160 drafts(deal, agentNow())
161 .filter((r) => unsent(r) && r.held !== null && r.held.until > day)
162 .map((draft) => ({ deal, draft })),
163 );
155164 const rows = deals().flatMap((deal) =>
156165 drafts(deal, agentNow())
157166 .filter((r) => pending(r, day))
@@ -319,7 +328,14 @@ export function terminal(
319328 }
320329
321330 function onReminder(key: string): boolean {
322 if (key !== "\r" && key !== "s" && key !== "e" && key !== "n" && key !== "u" && key !== "h") return false;
331 if (key === "H") {
332 showHeld = !showHeld;
333 reading = undefined;
334 cursor = 0;
335 said = "";
336 return true;
337 }
338 if (key !== "\r" && key !== "s" && key !== "e" && key !== "n" && key !== "u" && key !== "h" && key !== "B") return false;
323339 const row = reminderRows()[cursor];
324340 if (row === undefined) {
325341 said = "No reminder here.";
@@ -328,6 +344,20 @@ export function terminal(
328344 const { deal, draft: drafted } = row;
329345 const id = editKey(drafted);
330346 const draft = edited(drafted);
347 if (showHeld) {
348 if (key === "B")
349 said = report(
350 releaseReminder(db, me, { deadlineId: draft.deadline_id, partyId: draft.party_id, moment: draft.moment }),
351 `${draft.party_name}'s reminder is back in today's list.`,
352 );
353 else if (key === "\r") reading = reading === cursor ? undefined : cursor;
354 else said = "Held for a later morning; B brings it back to today.";
355 return true;
356 }
357 if (key === "B") {
358 said = "B brings back a held reminder: press H to see the held ones.";
359 return true;
360 }
331361 if (key === "\r") reading = reading === cursor ? undefined : cursor;
332362 if (key === "e") {
333363 if (drafted.sent_at !== null) said = "Already sent; its words are kept as they went.";
@@ -538,6 +568,7 @@ export function terminal(
538568 trail = [];
539569 } else if (key === "r") {
540570 view = "reminders";
571 showHeld = false;
541572 cursor = 0;
542573 reading = undefined;
543574 } else if (key === "/" && (view === "dates" || view === "week" || view === "reminders")) {
@@ -759,9 +790,10 @@ export function terminal(
759790 }
760791 } else {
761792 const rows = reminderRows();
762 if (rows.length === 0) lines.push(dim("Nothing goes out today."));
793 if (showHeld) lines.push(bold("Held reminders"), "");
794 if (rows.length === 0) lines.push(dim(showHeld ? "Nothing is held." : "Nothing goes out today."));
763795 rows.forEach(({ draft }, i) => {
764 const state = draft.sent_at !== null ? dim("sent") : draft.declined !== null ? dim("not sent") : draft.held !== null ? tint("overdue", heldFrom(draft.held).toLowerCase()) : draft.on < day ? tint("overdue", "late") : tint("soon", "to send");
796 const state = showHeld && draft.held !== null ? tint("soon", `back ${spoken(draft.held.until)}`) : draft.sent_at !== null ? dim("sent") : draft.declined !== null ? dim("not sent") : draft.held !== null ? tint("overdue", heldFrom(draft.held).toLowerCase()) : draft.on < day ? tint("overdue", "late") : tint("soon", "to send");
765797 const text = `${draft.party_name} (${PARTY_LABEL[draft.party_role].toLowerCase()}) · ${draft.label}, ${draft.address} · ${momentLabel(draft.moment, draft.lead_days).toLowerCase()}`;
766798 lines.push(`${i === cursor ? "▸" : " "} ${state.padEnd(16)} ${i === cursor ? bold(text) : text}`);
767799 if (reading === i) {
@@ -785,7 +817,9 @@ export function terminal(
785817 : view === "people"
786818 ? "P people · d dates · w this week · r reminders · q quit"
787819 : view === "reminders"
788 ? "j/k move · enter read · e edit · s send · n don't send · h tomorrow · u undo · / find · d dates · q quit"
820 ? showHeld
821 ? "j/k move · enter read · B bring back to today · H today's reminders · d dates · q quit"
822 : "j/k move · enter read · e edit · s send · n don't send · h tomorrow · u undo · H held · / find · d dates · q quit"
789823 : view === "messages"
790824 ? "j/k move · enter read · b back to the deal · d dates · q quit"
791825 : view === "timeline"

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs