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

Each date carries a short working note the agent keeps current, like "Appraisal ordered, AMC says Thursday", seen wherever the agent looks at that date #119

Merged opened this

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

Merged

mason/deal-clock:mason/113-each-date-carries-a-short-working-note-t → main 2 commits fork 1 thread · 1 unresolved

  • Merged. mason/113-each-date-carries-a-short-working-note-t was merged into main as c5b5b9f.

Review

Sign in to review this change.
17 files changed +276 −17
README.md +1
@@ -161,6 +161,7 @@ Signed out, `/` shows what deal-clock does, three short points, a still picture
161161 place: the clock, the client timeline, the calendar file and unsent drafts
162162 carry the new address, and reminders already sent keep their words. In the
163163 terminal open the deal and press A; over MCP, the `update_address` tool.
164 Each date also carries a short working note only you see, such as "Appraisal ordered, AMC says Thursday": write it in the date's sheet (Save note), or press T on a date in the terminal; it shows under the date, in This week and on the printed week, and never on a client page or in a message.
164165 15. **Put the samples back.** After the walk-through, an admin taps Sample
165166 deals below the clock, then Restore the sample deals and confirms: the four
166167 samples return as they were, dated from today, and the deals you opened are
contract/openapi.json +21 −3
@@ -758,6 +758,11 @@
758758 ],
759759 "description": "Who recorded the waiver."
760760 },
761 "note": {
762 "type": "string",
763 "maxLength": 200,
764 "description": "The agent's working note on this date; empty when none. Internal, never sent to a client."
765 },
761766 "owes_changed": {
762767 "type": [
763768 "object",
@@ -1828,7 +1833,7 @@
18281833 },
18291834 "/api/deals/{id}/deadlines/{deadline}": {
18301835 "patch": {
1831 "summary": "Change a date: lead_days sets how many days before it is due its first reminder goes out (a whole number, 1 to 30; 400 with field lead_days otherwise; an unsent draft is drafted again for the new day, a sent one keeps its words), and owes changes which party owes it (one of the party roles; 422 otherwise, 409 for a date already done or waived). Today's and later reminders are drafted to the new party; ones already sent stay as they were. Send either or both.",
1836 "summary": "Change a date: lead_days sets how many days before it is due its first reminder goes out (a whole number, 1 to 30; 400 with field lead_days otherwise; an unsent draft is drafted again for the new day, a sent one keeps its words), and owes changes which party owes it (one of the party roles; 422 otherwise, 409 for a date already done or waived). Today's and later reminders are drafted to the new party; ones already sent stay as they were. note sets the agent's working note on the date, one line of up to 200 characters, empty to clear it (400 with field note otherwise); it is internal and never reaches a client timeline, reminder or status update. Send any of them.",
18321837 "operationId": "patchApiDealsIdDeadlinesDeadline",
18331838 "parameters": [
18341839 {
@@ -1868,6 +1873,10 @@
18681873 "title",
18691874 "other_agent"
18701875 ]
1876 },
1877 "note": {
1878 "type": "string",
1879 "maxLength": 200
18711880 }
18721881 }
18731882 }
@@ -1876,7 +1885,7 @@
18761885 },
18771886 "responses": {
18781887 "200": {
1879 "description": "Change a date: lead_days sets how many days before it is due its first reminder goes out (a whole number, 1 to 30; 400 with field lead_days otherwise; an unsent draft is drafted again for the new day, a sent one keeps its words), and owes changes which party owes it (one of the party roles; 422 otherwise, 409 for a date already done or waived). Today's and later reminders are drafted to the new party; ones already sent stay as they were. Send either or both.",
1888 "description": "Change a date: lead_days sets how many days before it is due its first reminder goes out (a whole number, 1 to 30; 400 with field lead_days otherwise; an unsent draft is drafted again for the new day, a sent one keeps its words), and owes changes which party owes it (one of the party roles; 422 otherwise, 409 for a date already done or waived). Today's and later reminders are drafted to the new party; ones already sent stay as they were. note sets the agent's working note on the date, one line of up to 200 characters, empty to clear it (400 with field note otherwise); it is internal and never reaches a client timeline, reminder or status update. Send any of them.",
18801889 "content": {
18811890 "application/json": {
18821891 "schema": {
@@ -1896,12 +1905,16 @@
18961905 "title",
18971906 "other_agent"
18981907 ]
1908 },
1909 "note": {
1910 "type": "string"
18991911 }
19001912 },
19011913 "required": [
19021914 "id",
19031915 "lead_days",
1904 "owes"
1916 "owes",
1917 "note"
19051918 ]
19061919 }
19071920 }
@@ -2585,6 +2598,11 @@
25852598 ],
25862599 "description": "Who recorded the waiver."
25872600 },
2601 "note": {
2602 "type": "string",
2603 "maxLength": 200,
2604 "description": "The agent's working note on this date; empty when none. Internal, never sent to a client."
2605 },
25882606 "owes_changed": {
25892607 "type": [
25902608 "object",
docs/TECHNICAL.md +8
@@ -57,6 +57,14 @@ it; an unsent draft is redrafted, a sent one keeps its approved words. Set it wi
5757 `set_reminder_lead`, and `l` on a date in the terminal. Every door reads it as
5858 `lead_days` on the date.
5959
60 A date's working note (`deadline.note`, up to `NOTE_MAX` = 200 characters, one line, empty
61 clears it) is the agent's own: `setNote` (`src/deals.ts`, audited as `date.note` against the
62 deal) through the sheet form `POST /deadlines/:id/note` (a refusal is a 422 that keeps what was
63 typed), `PATCH /api/deals/:id/deadlines/:deadline` with `{"note": "…"}` (400 with field `note`),
64 MCP `set_date_note`, and `T` on a date in the terminal (the note shows beside the date there too). It is shown on the deal page, This week and `/week`, and is read by no
65 client-facing place: the client timeline, the calendar file, the spreadsheet, reminders and
66 status updates (`src/note.test.ts` checks each).
67
6068 Reminder moments (`MOMENTS`, `src/reminders.ts`): `before`, `day_of`, `late`
6169 and `moved` (*Date changed*). `moved` is drafted for the latest move of an open
6270 date, to the parties a `day_of` reminder goes to, dated the day of the move; its
src/activity.ts +1
@@ -23,6 +23,7 @@ const WORDS: Readonly<Record<string, string>> = {
2323 "date.done": "marked a date done",
2424 "date.waive": "waived a date",
2525 "date.owes": "changed who owes a date",
26 "date.note": "saved a date's working note",
2627 "date.lead": "changed when a date's reminder goes out",
2728 "date.add": "added a date",
2829 "date.remove": "removed a date",
src/db.ts +2
@@ -378,6 +378,8 @@ export const migrations: string[] = [
378378 `ALTER TABLE deadline ADD COLUMN owes_from TEXT`,
379379 `ALTER TABLE deadline ADD COLUMN owes_by TEXT`,
380380 `ALTER TABLE deadline ADD COLUMN owes_on TEXT`,
381 // The agent's working note on a date, one line. Internal: no client page, reminder or status update carries it.
382 `ALTER TABLE deadline ADD COLUMN note TEXT NOT NULL DEFAULT ''`,
381383 // A reminder the agent holds until a later morning. It is keyed like a
382384 // sent or declined one, so a moved date's notice is held once, not twice.
383385 `CREATE TABLE IF NOT EXISTS reminder_hold (
src/deals.ts +22
@@ -140,6 +140,8 @@ export interface Deadline {
140140 readonly owes_from: PartyRole | null;
141141 readonly owes_by: string | null;
142142 readonly owes_on: string | null;
143 /** The agent's working note on this date; empty when none. Internal: never shown to a client. */
144 readonly note: string;
143145 /** Days before it is due that its first reminder goes out. */
144146 readonly lead_days: number;
145147 }
@@ -200,6 +202,8 @@ export function message(value: unknown, min: number, max: number): string | unde
200202
201203 export const SUBJECT_MAX = 150;
202204 export const REASON_MAX = 200;
205 /** The longest working note on a date. */
206 export const NOTE_MAX = 200;
203207 /** Why a move is recorded when the agent takes the next-business-day suggestion. */
204208 export const ROLL_REASON = "Rolled to the next business day";
205209 export const BODY_MAX = 2000;
@@ -800,6 +804,24 @@ export function setOwes(
800804 return within(db, who, `${OWES_WHAT}:${deadline.owes}>${input.owes}`, dealId, ok(reread(db, deadline.id)));
801805 }
802806
807 /** What the audit trail calls saving a date's working note. */
808 export const NOTE_WHAT = "date.note";
809
810 /** Save the agent's working note on a date: one line, up to NOTE_MAX characters, empty to clear it. */
811 export function setNote(
812 db: Database,
813 who: Who,
814 input: { id: number; dealId?: number; note: unknown },
815 ): Result<Deadline> {
816 const { dealId, found } = deadlineFor(db, who, input.id, input.dealId);
817 if (!found.ok) return within(db, who, NOTE_WHAT, dealId, found);
818 const note = input.note === "" ? "" : line(input.note, 0, NOTE_MAX);
819 if (note === undefined)
820 return within(db, who, NOTE_WHAT, dealId, fail("invalid", `The note is one line of up to ${NOTE_MAX} characters.`, "note"));
821 db.query("UPDATE deadline SET note = ?1 WHERE id = ?2").run(note, input.id);
822 return within(db, who, NOTE_WHAT, dealId, ok(reread(db, input.id)));
823 }
824
803825 /** Whether `value` is a lead time: a whole number of days, 1 to 30. */
804826 const isLead = (value: unknown): value is number =>
805827 typeof value === "number" && Number.isInteger(value) && value >= LEAD_MIN && value <= LEAD_MAX;
src/mcp.ts +11
@@ -31,6 +31,7 @@ import {
3131 sendReminder,
3232 sendStatusUpdate,
3333 statusUpdates,
34 setNote,
3435 setReminderLead,
3536 setOwes,
3637 declineReminder,
@@ -185,6 +186,16 @@ export const tools: readonly Tool[] = [
185186 return moved.ok ? ok({ ...moved.value, conflicts: conflictsOf(db, who, moved.value.deal_id) }) : moved;
186187 },
187188 },
189 {
190 name: "set_date_note",
191 description: "Save the working note on a date: where it stands in a few words, one line of up to 200 characters, empty to clear it. Internal to the agent: it never reaches a client timeline, reminder or status update.",
192 inputSchema: {
193 type: "object",
194 properties: { id: { type: "integer" }, note: { type: "string", maxLength: 200 } },
195 required: ["id", "note"],
196 },
197 run: (db, who, args) => setNote(db, who, { id: Number(args.id), note: args.note }),
198 },
188199 {
189200 name: "set_reminder_lead",
190201 description: "Set how many days before it is due a date's first reminder goes out (a whole number, 1 to 30). An unsent draft is drafted again for the new day; a sent one keeps its words.",
src/note.test.ts added +130
@@ -0,0 +1,130 @@
1 /** A date's working note: the agent saves it at every door, sees it on their own pages, and no client-facing place carries it. */
2 import { afterAll, expect, test } from "bun:test";
3 import { mkdtempSync } from "node:fs";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { addDays, today } from "./dates.ts";
7 import { sheet as csv } from "./csv.ts";
8 import { calendar } from "./ics.ts";
9 import { agent } from "./env.ts";
10 import { drafts, statusDrafts } from "./reminders.ts";
11 import { timelinePage } from "./pages/timeline.ts";
12 import { forgetRationing } from "./security.ts";
13 import { serve } from "./server.ts";
14 import { sign } from "./who.ts";
15 import type { DealView } from "./deals.ts";
16
17 const KEY = "a-key-only-the-forge-holds";
18 const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-note-")), identityKey: KEY });
19 const base = `http://${server.hostname}:${server.port}`;
20 afterAll(() => server.stop(true));
21 const as = (role: string, name: string) => {
22 const id = `${name}|${name}|${role}|${Date.now() + 600_000}`;
23 return { "x-forge-identity": id, "x-forge-signature": sign(id, KEY) };
24 };
25 const me = as("user", "alice");
26 const json = { ...me, "content-type": "application/json" };
27 const NOTE = "Appraisal ordered, AMC says Thursday";
28 const SECRET = "INTERNAL-NOTE-XYZ";
29
30 async function fresh() {
31 forgetRationing();
32 const made = await fetch(base + "/api/deals", {
33 method: "POST",
34 headers: json,
35 body: JSON.stringify({ address: "3 Note Way", open_anyway: true, buyer: "B Buyer", seller: "S Seller", contract_date: addDays(today(), -20), closing_date: addDays(today(), 3) }),
36 });
37 const deal = (await made.json()) as DealView;
38 const d = deal.deadlines.find((x) => x.kind === "closing")!;
39 return { deal, d };
40 }
41 const read = async (id: number) => (await (await fetch(`${base}/api/deals/${id}`, { headers: me })).json()) as DealView;
42 const patch = (dealId: number, id: number, body: unknown, headers: Record<string, string> = json) =>
43 fetch(`${base}/api/deals/${dealId}/deadlines/${id}`, { method: "PATCH", headers, body: JSON.stringify(body) });
44
45 test("the PATCH route saves, clears and bounds the note, and the audit trail records it", async () => {
46 const { deal, d } = await fresh();
47 expect(d.note).toBe("");
48 const saved = await patch(deal.id, d.id, { note: NOTE });
49 expect(saved.status).toBe(200);
50 expect(await saved.json()).toMatchObject({ note: NOTE });
51 expect((await read(deal.id)).deadlines.find((x) => x.id === d.id)!.note).toBe(NOTE);
52 const long = await patch(deal.id, d.id, { note: "x".repeat(201) });
53 expect(long.status).toBe(400);
54 expect(await long.json()).toMatchObject({ field: "note" });
55 expect((await patch(deal.id, d.id, { note: "x".repeat(200) })).status).toBe(200);
56 expect((await patch(deal.id, d.id, { note: 5 })).status).toBe(400);
57 expect((await patch(deal.id, d.id, { note: "" })).status).toBe(200);
58 expect((await read(deal.id)).deadlines.find((x) => x.id === d.id)!.note).toBe("");
59 const anon = await patch(deal.id, d.id, { note: NOTE }, { "content-type": "application/json" });
60 expect(anon.status).toBeGreaterThanOrEqual(401);
61 const activity = await (await fetch(`${base}/activity`, { headers: as("admin", "root") })).text();
62 expect(activity).toContain("working note");
63 });
64
65 test("the MCP tool sets the note with the same rule", async () => {
66 const { deal, d } = await fresh();
67 const call = async (note: string) =>
68 JSON.stringify(await (await fetch(base + "/mcp", { method: "POST", headers: json, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "set_date_note", arguments: { id: d.id, note } } }) })).json());
69 expect(await call(NOTE)).toContain("Appraisal ordered");
70 expect((await read(deal.id)).deadlines.find((x) => x.id === d.id)!.note).toBe(NOTE);
71 expect(await call("y".repeat(201))).toContain("200 characters");
72 });
73
74 test("the sheet form saves without JavaScript; a refusal is a 422 that keeps what was typed", async () => {
75 const { deal, d } = await fresh();
76 const form = (note: string) =>
77 fetch(`${base}/deadlines/${d.id}/note`, {
78 method: "POST",
79 headers: { ...me, "content-type": "application/x-www-form-urlencoded" },
80 body: new URLSearchParams({ note, to: `/deals/${deal.id}` }),
81 redirect: "manual",
82 });
83 expect((await fetch(`${base}/deals/${deal.id}`, { headers: me }).then((r) => r.text()))).toContain(`action="/deadlines/${d.id}/note"`);
84 expect((await form(NOTE)).status).toBe(303);
85 const page = await (await fetch(`${base}/deals/${deal.id}`, { headers: me })).text();
86 expect(page).toContain(`<b>Note:</b> ${NOTE}`);
87 const tooLong = "<z>" + "z".repeat(210);
88 const refused = await form(tooLong);
89 expect(refused.status).toBe(422);
90 expect(await refused.text()).toContain(`value="&lt;z&gt;${"z".repeat(210)}"`);
91 });
92
93 test("the note shows on the deal page, This week and the printed week, and nowhere a client reads", async () => {
94 const { deal, d } = await fresh();
95 expect((await patch(deal.id, d.id, { note: SECRET })).status).toBe(200);
96 const get = async (path: string) => (await fetch(base + path, { headers: me })).text();
97 expect(await get(`/deals/${deal.id}`)).toContain(SECRET);
98 const clock = await get("/");
99 const card = clock.slice(clock.indexOf('id="week"'));
100 expect(card).toContain(SECRET);
101 expect(await get("/week")).toContain(SECRET);
102
103 const full = await read(deal.id);
104 expect(timelinePage({ who: { role: "user", id: "u", name: "alice" }, deal: full, on: today() })).not.toContain(SECRET);
105 expect(await get(`/deals/${deal.id}/timeline`)).not.toContain(SECRET);
106 expect(csv([full])).not.toContain(SECRET);
107 expect(calendar(full, "x.example")).not.toContain(SECRET);
108 expect(JSON.stringify(drafts(full, agent))).not.toContain(SECRET);
109 expect(JSON.stringify(statusDrafts(full, agent))).not.toContain(SECRET);
110 const timelineTool = await (await fetch(base + "/mcp", { method: "POST", headers: json, body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "client_timeline", arguments: { id: deal.id } } }) })).text();
111 expect(timelineTool).not.toContain(SECRET);
112 });
113
114 test("the sample deals carry a note on a date", async () => {
115 const sample = await get();
116 expect(sample).toContain("Appraisal ordered, AMC says Thursday");
117 async function get() {
118 forgetRationing();
119 return (await fetch(base + "/week", { headers: me })).text();
120 }
121 });
122
123 test("an owes change is not applied when the note beside it is refused", async () => {
124 const { deal, d } = await fresh();
125 const before = d.owes;
126 const other = before === "buyer" ? "seller" : "buyer";
127 const res = await patch(deal.id, d.id, { owes: other, note: "x".repeat(201) });
128 expect(res.status).toBe(400);
129 expect((await read(deal.id)).deadlines.find((x) => x.id === d.id)!.owes).toBe(before);
130 });
src/pages/clock.ts +1 −1
@@ -100,7 +100,7 @@ export function weekCard(deals: readonly DealView[], on: string, q = ""): string
100100 (g) => `<h3 class="week-day">${escape(g.heading)}</h3>
101101 <ul class="week-list">${g.items
102102 .map(({ deal, deadline: d }) =>
103 weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}</b><small class="muted">${escape(deal.address)} · ${owedBy(deal, d)}</small>${d.nonBusinessDay === null ? "" : `<small class="muted">Not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</small>`}</span>${badge(d, on)}</a></li>`),
103 weekRows(`${on}|${print(deal)}|${d.id}`, () => `<li><a class="week-row" ${opens(deal, d)}><span class="week-what"><b>${escape(d.label)}</b><small class="muted">${escape(deal.address)} · ${owedBy(deal, d)}</small>${d.nonBusinessDay === null ? "" : `<small class="muted">Not a business day · next is ${escape(spoken(d.nonBusinessDay.next))}</small>`}${d.note === "" ? "" : `<small class="muted">${escape(d.note)}</small>`}</span>${badge(d, on)}</a></li>`),
104104 )
105105 .join("")}</ul>`,
106106 )
src/pages/deal.ts +5 −2
@@ -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, owesChangedLine, rollForm, draftItem, dueLine, outboxLine, owedBy, releaseForm, sheet, sheetId } from "./sheet.ts";
19 import { badge, conflictLines, nonBusinessLine, noteLine, owesChangedLine, rollForm, draftItem, dueLine, outboxLine, owedBy, releaseForm, sheet, sheetId } from "./sheet.ts";
2020
2121 const roleOptions = (selected?: string): string =>
2222 PARTY_ROLES.map(
@@ -93,6 +93,8 @@ export function dealPage(input: {
9393 deal: DealView;
9494 on: string;
9595 notice?: string | undefined;
96 /** A refused note: the date and what was typed, so the form keeps it. */
97 typed?: { id: number; note: string } | undefined;
9698 /** The sent reminder the notice offers to open. */
9799 open?: number | undefined;
98100 /** An address that was refused: what was typed and why, to show beside the field. */
@@ -121,6 +123,7 @@ export function dealPage(input: {
121123 <p class="muted small">${escape(dueLine(d, on))}${d.moves.length > 0 ? ` · moved ${d.moves.length}×` : ""}</p>
122124 <p class="small">${owedBy(deal, d)}</p>
123125 ${owesChangedLine(d)}
126 ${noteLine(d)}
124127 ${nonBusinessLine(d)}${may ? rollForm(d, path) : ""}
125128 </div>
126129 <button class="button button-quiet" popovertarget="${sheetId(d)}">Open</button>
@@ -187,7 +190,7 @@ export function dealPage(input: {
187190 <h2>Messages</h2>
188191 ${messages(deal, may, agent ?? defaults, path)}
189192 </section>
190 ${deal.deadlines.map((d) => sheet(deal, d, who, on, path, agent)).join("")}
193 ${deal.deadlines.map((d) => sheet(deal, d, who, on, path, agent, input.typed)).join("")}
191194 </div>
192195 ${forms}
193196 ${fellForm(deal, path, may)}
src/pages/sheet.ts +12 −3
@@ -5,7 +5,7 @@
55 * script; the forms post and come back.
66 */
77
8 import { BODY_MAX, canChange, ROLL_REASON, REASON_MAX, SUBJECT_MAX, type DealView, type DeadlineView } from "../deals.ts";
8 import { BODY_MAX, canChange, NOTE_MAX, ROLL_REASON, REASON_MAX, SUBJECT_MAX, type DealView, type DeadlineView } from "../deals.ts";
99 import { relative, short, spoken, urgencyOf, type Urgency } from "../dates.ts";
1010 import { isOpen, isWaivable, LEAD_MAX, LEAD_MIN, PARTY_LABEL, PARTY_ROLES } from "../deadlines.ts";
1111 import { escape } from "../http.ts";
@@ -50,6 +50,10 @@ export const owesChangedLine = (d: DeadlineView): string =>
5050 ? ""
5151 : `<p class="muted small">${escape(`Owed by changed from ${PARTY_LABEL[d.owes_changed.from]} to ${PARTY_LABEL[d.owes]} by ${d.owes_changed.by} on ${spoken(d.owes_changed.on)}`)}</p>`;
5252
53 /** The agent's working note under a date, or nothing when it has none. Internal: only the agent's own pages call it. */
54 export const noteLine = (d: DeadlineView): string =>
55 d.note === "" ? "" : `<p class="small date-note"><b>Note:</b> ${escape(d.note)}</p>`;
56
5357 /** "Sat, Nov 28 · not a business day · next is Mon, Nov 30" for a flagged date, else nothing. */
5458 export const nonBusinessLine = (d: DeadlineView): string =>
5559 d.nonBusinessDay === null
@@ -180,7 +184,7 @@ export function draftItem(draft: Draft, on: string, may: boolean, to: string): s
180184 export const draftLink = (draft: Draft, on: string): string =>
181185 `<li class="draft"><a class="draft-open" href="/deals/${draft.deal_id}#sheet-${draft.deadline_id}" data-sheet="sheet-${draft.deadline_id}" data-sheets="/deals/${draft.deal_id}/sheets">${draftLine(draft, on, true)}</a></li>`;
182186
183 export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: string, agent: Agent = defaults): string {
187 export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: string, agent: Agent = defaults, typed?: { id: number; note: string }): string {
184188 const id = sheetId(d);
185189 const may = canChange(who, deal);
186190 const drafts = isOpen(d) ? draftsFor(deal, d, agent) : [];
@@ -242,6 +246,11 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to:
242246 </form>`
243247 : ""
244248 }
249 <form class="move" method="post" action="/deadlines/${d.id}/note">${hidden({ to })}
250 <label>Note<input class="input" name="note" maxlength="${NOTE_MAX}" autocomplete="off" value="${escape(typed?.id === d.id ? typed.note : d.note)}" placeholder="e.g. Appraisal ordered, AMC says Thursday"></label>
251 <button class="button button-quiet">Save note</button>
252 </form>
253 <p class="muted small">Only you see the note; it is never sent to a client.</p>
245254 <form class="move" method="post" action="/deadlines/${d.id}/lead">${hidden({ to })}
246255 <label>Remind me this many days before<input class="input" type="number" name="lead_days" min="${LEAD_MIN}" max="${LEAD_MAX}" step="1" value="${d.lead_days}" required></label>
247256 <button class="button button-quiet">Set reminder</button>
@@ -269,7 +278,7 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to:
269278 </div>
270279 <button class="button button-quiet" popovertarget="${id}" popovertargetaction="hide" aria-label="Close">✕</button>
271280 </header>
272 <section><h3>Who owes what</h3><p>${owedBy(deal, d)}</p>${owesChangedLine(d)}${d.what === "" ? "" : `<p>${escape(d.what)}</p>`}</section>
281 <section><h3>Who owes what</h3><p>${owedBy(deal, d)}</p>${owesChangedLine(d)}${noteLine(d)}${d.what === "" ? "" : `<p>${escape(d.what)}</p>`}</section>
273282 ${conflictLines(deal, d)}
274283 ${nonBusinessLine(d)}${may ? rollForm(d, to) : ""}
275284 ${moves}
src/pages/week.ts +1
@@ -35,6 +35,7 @@ export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: re
3535 <p class="timeline-date">${escape(deal.address)}</p>
3636 <p class="timeline-label"><b>${escape(d.label)}</b></p>
3737 <p class="timeline-owner">${escape(role)}${name === undefined ? "" : ` · ${escape(name)}`}</p>
38 ${d.note === "" ? "" : `<p class="timeline-owner">${escape(d.note)}</p>`}
3839 <p class="timeline-status"><span aria-hidden="true">${s.mark}</span> ${s.word}</p>
3940 </li>`;
4041 })
src/routes.ts +32 −4
@@ -67,6 +67,9 @@ import {
6767 sendStatusUpdate,
6868 statusUpdates,
6969 setReminderLead,
70 setNote,
71 line,
72 NOTE_MAX,
7073 setOwes,
7174 declineReminder,
7275 holdReminder,
@@ -243,6 +246,7 @@ export const DEAL: Schema = {
243246 done_at: { type: ["string", "null"] },
244247 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." },
245248 waived_by: { type: ["string", "null"], description: "Who recorded the waiver." },
249 note: { type: "string", maxLength: 200, description: "The agent's working note on this date; empty when none. Internal, never sent to a client." },
246250 owes_changed: {
247251 type: ["object", "null"],
248252 description: "The latest change of Owed by: the role it had (from), who changed it (by) and the day (on). Null when it was never changed.",
@@ -989,6 +993,23 @@ export const routes: readonly Route[] = [
989993 return done(set, backTo(f.to));
990994 },
991995 },
996 {
997 method: "POST",
998 path: "/deadlines/:id/note",
999 handle: async (c) => {
1000 const f = await form(c);
1001 if (f instanceof Response) return f;
1002 const id = Number(c.params.id);
1003 const set = setNote(c.db, c.who, { id, note: f.note });
1004 if (set.ok) return done(set, backTo(f.to), set.value.note === "" ? `Note cleared on ${set.value.label}.` : `Note saved on ${set.value.label}.`);
1005 const deal = c.db.query<{ deal_id: number }, [number]>("SELECT deal_id FROM deadline WHERE id = ?1").get(id)?.deal_id;
1006 const found = deal === undefined ? undefined : getDeal(c.db, c.who, { id: deal });
1007 // A refused note comes back as that deal's page, saying why, with what was typed in the field.
1008 if (found?.ok && set.error === "invalid")
1009 return html(dealPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), deal: found.value, on: today(), notice: set.message, typed: { id, note: typeof f.note === "string" ? f.note : "" } }), STATUS[set.error]);
1010 return done(set, backTo(f.to));
1011 },
1012 },
9921013 {
9931014 method: "POST",
9941015 path: "/deadlines/:id/lead",
@@ -1412,9 +1433,16 @@ export const routes: readonly Route[] = [
14121433 const sent = fields(body);
14131434 const lead = sent.lead_days;
14141435 const target = { id: Number(c.params.deadline), dealId: Number(c.params.id) };
1436 // A note outside its rule is refused before anything else in the request is applied.
1437 if ("note" in sent && line(sent.note, 0, NOTE_MAX) === undefined)
1438 return json({ error: "invalid", message: `The note is one line of up to ${NOTE_MAX} characters.`, field: "note" }, 400);
14151439 if ("owes" in sent) {
14161440 const handed = setOwes(c.db, c.who, { ...target, owes: sent.owes });
1417 if (!handed.ok || !("lead_days" in sent)) return answer(handed);
1441 if (!handed.ok || !("lead_days" in sent || "note" in sent)) return answer(handed);
1442 }
1443 if ("note" in sent) {
1444 const noted = setNote(c.db, c.who, { ...target, note: sent.note });
1445 if (!noted.ok || !("lead_days" in sent)) return answer(noted);
14181446 }
14191447 const set = setReminderLead(c.db, c.who, { id: Number(c.params.deadline), dealId: Number(c.params.id), leadDays: typeof lead === "number" ? lead : Number.NaN });
14201448 // A lead outside 1–30 is a bad field: 400, naming it.
@@ -1423,9 +1451,9 @@ export const routes: readonly Route[] = [
14231451 },
14241452 api: {
14251453 summary:
1426 "Change a date: lead_days sets how many days before it is due its first reminder goes out (a whole number, 1 to 30; 400 with field lead_days otherwise; an unsent draft is drafted again for the new day, a sent one keeps its words), and owes changes which party owes it (one of the party roles; 422 otherwise, 409 for a date already done or waived). Today's and later reminders are drafted to the new party; ones already sent stay as they were. Send either or both.",
1427 body: { type: "object", properties: { lead_days: { type: "integer", minimum: 1, maximum: 30 }, owes: ROLE } },
1428 answer: { type: "object", properties: { id: { type: "integer" }, lead_days: { type: "integer" }, owes: ROLE }, required: ["id", "lead_days", "owes"] },
1454 "Change a date: lead_days sets how many days before it is due its first reminder goes out (a whole number, 1 to 30; 400 with field lead_days otherwise; an unsent draft is drafted again for the new day, a sent one keeps its words), and owes changes which party owes it (one of the party roles; 422 otherwise, 409 for a date already done or waived). Today's and later reminders are drafted to the new party; ones already sent stay as they were. note sets the agent's working note on the date, one line of up to 200 characters, empty to clear it (400 with field note otherwise); it is internal and never reaches a client timeline, reminder or status update. Send any of them.",
1455 body: { type: "object", properties: { lead_days: { type: "integer", minimum: 1, maximum: 30 }, owes: ROLE, note: { type: "string", maxLength: 200 } } },
1456 answer: { type: "object", properties: { id: { type: "integer" }, lead_days: { type: "integer" }, owes: ROLE, note: { type: "string" } }, required: ["id", "lead_days", "owes", "note"] },
14291457 },
14301458 },
14311459 {
src/sample.ts +6
@@ -27,6 +27,8 @@ interface Sample {
2727 readonly waived?: readonly string[];
2828 readonly custom?: readonly [string, number, PartyRole, string][];
2929 readonly moved?: readonly [string, number, string];
30 /** The agent's working note on a date: date kind, note. */
31 readonly notes?: readonly (readonly [string, string])[];
3032 /** A reminder already sent, in the agent's own edited words: date kind, party role, moment, subject, body. */
3133 readonly sent?: readonly [string, PartyRole, "before" | "day_of", string, string];
3234 }
@@ -65,6 +67,7 @@ const SAMPLES: readonly Sample[] = [
6567 ["other_agent", "Alicia Moreno, Moreno & Co.", "[email protected]"],
6668 ],
6769 done: ["earnest"],
70 notes: [["inspection", "Inspector booked for Friday 9am; seller will leave the attic open"]],
6871 custom: [["HOA documents review ends", 1, "buyer", "Read the HOA budget, rules and minutes; object in writing if needed"]],
6972 },
7073 {
@@ -81,6 +84,7 @@ const SAMPLES: readonly Sample[] = [
8184 done: ["earnest", "inspection", "title"],
8285 custom: [["Repair credit agreed", 5, "seller", "Signed amendment for the roof repair credit"]],
8386 moved: ["appraisal", 2, "Appraiser rescheduled — access to the property"],
87 notes: [["appraisal", "Appraisal ordered, AMC says Thursday"]],
8488 },
8589 {
8690 address: "2210 Juniper Court",
@@ -235,6 +239,8 @@ function writeSamples(db: Database, on: string): void {
235239 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);
236240 for (const kind of s.waived ?? [])
237241 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);
242 for (const [kind, note] of s.notes ?? [])
243 db.query("UPDATE deadline SET note = ?1 WHERE deal_id = ?2 AND kind = ?3").run(note, deal.id, kind);
238244 for (const [label, days, owes, what] of s.custom ?? [])
239245 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);
240246 if (s.sent !== undefined) {
src/server.test.ts +1
@@ -183,6 +183,7 @@ test("the MCP server lists the tools and calls them as the caller", async () =>
183183 "reopen_deal",
184184 "waive_date",
185185 "move_date",
186 "set_date_note",
186187 "set_reminder_lead",
187188 "amend_deal",
188189 "send_reminder",
src/terminal.test.ts +11
@@ -763,3 +763,14 @@ test("a date on a weekend shows its next business day, and N rolls it there with
763763 t.press("N");
764764 expect(lines(t).join("\n")).toContain("already on a business day");
765765 });
766
767 test("T sets and clears a date's note, shown beside the date, through setNote", () => {
768 const t = terminal(db, alice, context);
769 goTo(t, "Closing");
770 press(t, "T", "Title co. confirms Friday\r");
771 expect(under(t)).toContain("note: Title co. confirms Friday");
772 expect(db.query("SELECT count(*) AS n FROM deadline WHERE note = ?1").get("Title co. confirms Friday")).toEqual({ n: 1 });
773 press(t, "T", "\r");
774 expect(under(t)).not.toContain("note:");
775 expect(db.query("SELECT count(*) AS n FROM deadline WHERE note = ?1").get("Title co. confirms Friday")).toEqual({ n: 0 });
776 });
src/terminal.ts +11 −4
@@ -46,6 +46,7 @@ import {
4646 moveDeadline,
4747 withConflicts,
4848 removeDeadline,
49 setNote,
4950 setReminderLead,
5051 removeParty,
5152 sendReminder,
@@ -195,7 +196,7 @@ export function terminal(
195196
196197 function onDate(key: string): boolean {
197198 const row = dateRows()[cursor];
198 if (!["x", "u", "W", "m", "N", "l", "o", "\r"].includes(key)) return false;
199 if (!["x", "u", "W", "m", "N", "l", "T", "o", "\r"].includes(key)) return false;
199200 if (row === undefined) {
200201 said = "No date here.";
201202 return true;
@@ -229,6 +230,11 @@ export function terminal(
229230 return report(set, () => `${date.label}: ${remindsLine(set.ok ? set.value.lead_days : 0).toLowerCase()}.`);
230231 },
231232 );
233 if (key === "T")
234 ask(deal, [`Note for ${date.label} (empty clears it${date.note === "" ? "" : `; now: ${date.note}`})`], ([note]) => {
235 const set = setNote(db, me, { id: date.id, note });
236 return report(set, () => (set.ok && set.value.note === "" ? `Note cleared on ${date.label}.` : `Note saved on ${date.label}.`));
237 });
232238 if ((key === "o" || key === "\r") && view === "dates") {
233239 view = "deal";
234240 dealId = deal.id;
@@ -658,7 +664,8 @@ export function terminal(
658664 const moved = date.moves.length > 0 ? dim(` moved: ${date.moves.at(-1)!.reason}`) : "";
659665 const flag = date.nonBusinessDay === null ? "" : dim(` not a business day · next is ${spoken(date.nonBusinessDay.next)} (N moves it)`);
660666 const lead = isOpen(date) ? dim(` reminds ${date.lead_days}d before`) : "";
661 return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${flag}${lead}${moved}`;
667 const note = date.note === "" ? "" : dim(` note: ${date.note}`);
668 return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${flag}${lead}${moved}${note}`;
662669 };
663670
664671 function screen(): string[] {
@@ -825,8 +832,8 @@ export function terminal(
825832 : view === "timeline"
826833 ? "b back to the deal · d dates · q quit"
827834 : view === "deal"
828 ? "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"
829 : `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`;
835 ? "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 · T note · 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"
836 : `j/k move · x done · W waive · u reopen · m move · N next business day · l lead · T note · 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`;
830837 lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys));
831838 }
832839 return lines;

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs