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
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/113-each-date-carries-a-short-working-note-t → main 2 commits fork 1 thread · 1 unresolved
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 | ||
| 161 | 161 | place: the clock, the client timeline, the calendar file and unsent drafts |
| 162 | 162 | carry the new address, and reminders already sent keep their words. In the |
| 163 | 163 | 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. | |
| 164 | 165 | 15. **Put the samples back.** After the walk-through, an admin taps Sample |
| 165 | 166 | deals below the clock, then Restore the sample deals and confirms: the four |
| 166 | 167 | samples return as they were, dated from today, and the deals you opened are |
contract/openapi.json +21 −3
| @@ -758,6 +758,11 @@ | ||
| 758 | 758 | ], |
| 759 | 759 | "description": "Who recorded the waiver." |
| 760 | 760 | }, |
| 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 | }, | |
| 761 | 766 | "owes_changed": { |
| 762 | 767 | "type": [ |
| 763 | 768 | "object", |
| @@ -1828,7 +1833,7 @@ | ||
| 1828 | 1833 | }, |
| 1829 | 1834 | "/api/deals/{id}/deadlines/{deadline}": { |
| 1830 | 1835 | "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.", | |
| 1832 | 1837 | "operationId": "patchApiDealsIdDeadlinesDeadline", |
| 1833 | 1838 | "parameters": [ |
| 1834 | 1839 | { |
| @@ -1868,6 +1873,10 @@ | ||
| 1868 | 1873 | "title", |
| 1869 | 1874 | "other_agent" |
| 1870 | 1875 | ] |
| 1876 | }, | |
| 1877 | "note": { | |
| 1878 | "type": "string", | |
| 1879 | "maxLength": 200 | |
| 1871 | 1880 | } |
| 1872 | 1881 | } |
| 1873 | 1882 | } |
| @@ -1876,7 +1885,7 @@ | ||
| 1876 | 1885 | }, |
| 1877 | 1886 | "responses": { |
| 1878 | 1887 | "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.", | |
| 1880 | 1889 | "content": { |
| 1881 | 1890 | "application/json": { |
| 1882 | 1891 | "schema": { |
| @@ -1896,12 +1905,16 @@ | ||
| 1896 | 1905 | "title", |
| 1897 | 1906 | "other_agent" |
| 1898 | 1907 | ] |
| 1908 | }, | |
| 1909 | "note": { | |
| 1910 | "type": "string" | |
| 1899 | 1911 | } |
| 1900 | 1912 | }, |
| 1901 | 1913 | "required": [ |
| 1902 | 1914 | "id", |
| 1903 | 1915 | "lead_days", |
| 1904 | "owes" | |
| 1916 | "owes", | |
| 1917 | "note" | |
| 1905 | 1918 | ] |
| 1906 | 1919 | } |
| 1907 | 1920 | } |
| @@ -2585,6 +2598,11 @@ | ||
| 2585 | 2598 | ], |
| 2586 | 2599 | "description": "Who recorded the waiver." |
| 2587 | 2600 | }, |
| 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 | }, | |
| 2588 | 2606 | "owes_changed": { |
| 2589 | 2607 | "type": [ |
| 2590 | 2608 | "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 | ||
| 57 | 57 | `set_reminder_lead`, and `l` on a date in the terminal. Every door reads it as |
| 58 | 58 | `lead_days` on the date. |
| 59 | 59 | |
| 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 | ||
| 60 | 68 | Reminder moments (`MOMENTS`, `src/reminders.ts`): `before`, `day_of`, `late` |
| 61 | 69 | and `moved` (*Date changed*). `moved` is drafted for the latest move of an open |
| 62 | 70 | 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>> = { | ||
| 23 | 23 | "date.done": "marked a date done", |
| 24 | 24 | "date.waive": "waived a date", |
| 25 | 25 | "date.owes": "changed who owes a date", |
| 26 | "date.note": "saved a date's working note", | |
| 26 | 27 | "date.lead": "changed when a date's reminder goes out", |
| 27 | 28 | "date.add": "added a date", |
| 28 | 29 | "date.remove": "removed a date", |
src/db.ts +2
| @@ -378,6 +378,8 @@ export const migrations: string[] = [ | ||
| 378 | 378 | `ALTER TABLE deadline ADD COLUMN owes_from TEXT`, |
| 379 | 379 | `ALTER TABLE deadline ADD COLUMN owes_by TEXT`, |
| 380 | 380 | `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 ''`, | |
| 381 | 383 | // A reminder the agent holds until a later morning. It is keyed like a |
| 382 | 384 | // sent or declined one, so a moved date's notice is held once, not twice. |
| 383 | 385 | `CREATE TABLE IF NOT EXISTS reminder_hold ( |
src/deals.ts +22
| @@ -140,6 +140,8 @@ export interface Deadline { | ||
| 140 | 140 | readonly owes_from: PartyRole | null; |
| 141 | 141 | readonly owes_by: string | null; |
| 142 | 142 | 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; | |
| 143 | 145 | /** Days before it is due that its first reminder goes out. */ |
| 144 | 146 | readonly lead_days: number; |
| 145 | 147 | } |
| @@ -200,6 +202,8 @@ export function message(value: unknown, min: number, max: number): string | unde | ||
| 200 | 202 | |
| 201 | 203 | export const SUBJECT_MAX = 150; |
| 202 | 204 | export const REASON_MAX = 200; |
| 205 | /** The longest working note on a date. */ | |
| 206 | export const NOTE_MAX = 200; | |
| 203 | 207 | /** Why a move is recorded when the agent takes the next-business-day suggestion. */ |
| 204 | 208 | export const ROLL_REASON = "Rolled to the next business day"; |
| 205 | 209 | export const BODY_MAX = 2000; |
| @@ -800,6 +804,24 @@ export function setOwes( | ||
| 800 | 804 | return within(db, who, `${OWES_WHAT}:${deadline.owes}>${input.owes}`, dealId, ok(reread(db, deadline.id))); |
| 801 | 805 | } |
| 802 | 806 | |
| 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 | ||
| 803 | 825 | /** Whether `value` is a lead time: a whole number of days, 1 to 30. */ |
| 804 | 826 | const isLead = (value: unknown): value is number => |
| 805 | 827 | typeof value === "number" && Number.isInteger(value) && value >= LEAD_MIN && value <= LEAD_MAX; |
src/mcp.ts +11
| @@ -31,6 +31,7 @@ import { | ||
| 31 | 31 | sendReminder, |
| 32 | 32 | sendStatusUpdate, |
| 33 | 33 | statusUpdates, |
| 34 | setNote, | |
| 34 | 35 | setReminderLead, |
| 35 | 36 | setOwes, |
| 36 | 37 | declineReminder, |
| @@ -185,6 +186,16 @@ export const tools: readonly Tool[] = [ | ||
| 185 | 186 | return moved.ok ? ok({ ...moved.value, conflicts: conflictsOf(db, who, moved.value.deal_id) }) : moved; |
| 186 | 187 | }, |
| 187 | 188 | }, |
| 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 | }, | |
| 188 | 199 | { |
| 189 | 200 | name: "set_reminder_lead", |
| 190 | 201 | 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="<z>${"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 | ||
| 100 | 100 | (g) => `<h3 class="week-day">${escape(g.heading)}</h3> |
| 101 | 101 | <ul class="week-list">${g.items |
| 102 | 102 | .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>`), | |
| 104 | 104 | ) |
| 105 | 105 | .join("")}</ul>`, |
| 106 | 106 | ) |
src/pages/deal.ts +5 −2
| @@ -16,7 +16,7 @@ import { partyContact } from "./contact.ts"; | ||
| 16 | 16 | import { confirmRemove } from "./confirm.ts"; |
| 17 | 17 | import { layout } from "./layout.ts"; |
| 18 | 18 | 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"; | |
| 20 | 20 | |
| 21 | 21 | const roleOptions = (selected?: string): string => |
| 22 | 22 | PARTY_ROLES.map( |
| @@ -93,6 +93,8 @@ export function dealPage(input: { | ||
| 93 | 93 | deal: DealView; |
| 94 | 94 | on: string; |
| 95 | 95 | 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; | |
| 96 | 98 | /** The sent reminder the notice offers to open. */ |
| 97 | 99 | open?: number | undefined; |
| 98 | 100 | /** An address that was refused: what was typed and why, to show beside the field. */ |
| @@ -121,6 +123,7 @@ export function dealPage(input: { | ||
| 121 | 123 | <p class="muted small">${escape(dueLine(d, on))}${d.moves.length > 0 ? ` · moved ${d.moves.length}×` : ""}</p> |
| 122 | 124 | <p class="small">${owedBy(deal, d)}</p> |
| 123 | 125 | ${owesChangedLine(d)} |
| 126 | ${noteLine(d)} | |
| 124 | 127 | ${nonBusinessLine(d)}${may ? rollForm(d, path) : ""} |
| 125 | 128 | </div> |
| 126 | 129 | <button class="button button-quiet" popovertarget="${sheetId(d)}">Open</button> |
| @@ -187,7 +190,7 @@ export function dealPage(input: { | ||
| 187 | 190 | <h2>Messages</h2> |
| 188 | 191 | ${messages(deal, may, agent ?? defaults, path)} |
| 189 | 192 | </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("")} | |
| 191 | 194 | </div> |
| 192 | 195 | ${forms} |
| 193 | 196 | ${fellForm(deal, path, may)} |
src/pages/sheet.ts +12 −3
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | * script; the forms post and come back. |
| 6 | 6 | */ |
| 7 | 7 | |
| 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"; | |
| 9 | 9 | import { relative, short, spoken, urgencyOf, type Urgency } from "../dates.ts"; |
| 10 | 10 | import { isOpen, isWaivable, LEAD_MAX, LEAD_MIN, PARTY_LABEL, PARTY_ROLES } from "../deadlines.ts"; |
| 11 | 11 | import { escape } from "../http.ts"; |
| @@ -50,6 +50,10 @@ export const owesChangedLine = (d: DeadlineView): string => | ||
| 50 | 50 | ? "" |
| 51 | 51 | : `<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>`; |
| 52 | 52 | |
| 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 | ||
| 53 | 57 | /** "Sat, Nov 28 · not a business day · next is Mon, Nov 30" for a flagged date, else nothing. */ |
| 54 | 58 | export const nonBusinessLine = (d: DeadlineView): string => |
| 55 | 59 | d.nonBusinessDay === null |
| @@ -180,7 +184,7 @@ export function draftItem(draft: Draft, on: string, may: boolean, to: string): s | ||
| 180 | 184 | export const draftLink = (draft: Draft, on: string): string => |
| 181 | 185 | `<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>`; |
| 182 | 186 | |
| 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 { | |
| 184 | 188 | const id = sheetId(d); |
| 185 | 189 | const may = canChange(who, deal); |
| 186 | 190 | const drafts = isOpen(d) ? draftsFor(deal, d, agent) : []; |
| @@ -242,6 +246,11 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: | ||
| 242 | 246 | </form>` |
| 243 | 247 | : "" |
| 244 | 248 | } |
| 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> | |
| 245 | 254 | <form class="move" method="post" action="/deadlines/${d.id}/lead">${hidden({ to })} |
| 246 | 255 | <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> |
| 247 | 256 | <button class="button button-quiet">Set reminder</button> |
| @@ -269,7 +278,7 @@ export function sheet(deal: DealView, d: DeadlineView, who: Who, on: string, to: | ||
| 269 | 278 | </div> |
| 270 | 279 | <button class="button button-quiet" popovertarget="${id}" popovertargetaction="hide" aria-label="Close">✕</button> |
| 271 | 280 | </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> | |
| 273 | 282 | ${conflictLines(deal, d)} |
| 274 | 283 | ${nonBusinessLine(d)}${may ? rollForm(d, to) : ""} |
| 275 | 284 | ${moves} |
src/pages/week.ts +1
| @@ -35,6 +35,7 @@ export function weekPage(input: { who: Who; agent?: Agent | undefined; deals: re | ||
| 35 | 35 | <p class="timeline-date">${escape(deal.address)}</p> |
| 36 | 36 | <p class="timeline-label"><b>${escape(d.label)}</b></p> |
| 37 | 37 | <p class="timeline-owner">${escape(role)}${name === undefined ? "" : ` · ${escape(name)}`}</p> |
| 38 | ${d.note === "" ? "" : `<p class="timeline-owner">${escape(d.note)}</p>`} | |
| 38 | 39 | <p class="timeline-status"><span aria-hidden="true">${s.mark}</span> ${s.word}</p> |
| 39 | 40 | </li>`; |
| 40 | 41 | }) |
src/routes.ts +32 −4
| @@ -67,6 +67,9 @@ import { | ||
| 67 | 67 | sendStatusUpdate, |
| 68 | 68 | statusUpdates, |
| 69 | 69 | setReminderLead, |
| 70 | setNote, | |
| 71 | line, | |
| 72 | NOTE_MAX, | |
| 70 | 73 | setOwes, |
| 71 | 74 | declineReminder, |
| 72 | 75 | holdReminder, |
| @@ -243,6 +246,7 @@ export const DEAL: Schema = { | ||
| 243 | 246 | done_at: { type: ["string", "null"] }, |
| 244 | 247 | 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." }, |
| 245 | 248 | 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." }, | |
| 246 | 250 | owes_changed: { |
| 247 | 251 | type: ["object", "null"], |
| 248 | 252 | 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[] = [ | ||
| 989 | 993 | return done(set, backTo(f.to)); |
| 990 | 994 | }, |
| 991 | 995 | }, |
| 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 | }, | |
| 992 | 1013 | { |
| 993 | 1014 | method: "POST", |
| 994 | 1015 | path: "/deadlines/:id/lead", |
| @@ -1412,9 +1433,16 @@ export const routes: readonly Route[] = [ | ||
| 1412 | 1433 | const sent = fields(body); |
| 1413 | 1434 | const lead = sent.lead_days; |
| 1414 | 1435 | 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); | |
| 1415 | 1439 | if ("owes" in sent) { |
| 1416 | 1440 | 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); | |
| 1418 | 1446 | } |
| 1419 | 1447 | const set = setReminderLead(c.db, c.who, { id: Number(c.params.deadline), dealId: Number(c.params.id), leadDays: typeof lead === "number" ? lead : Number.NaN }); |
| 1420 | 1448 | // A lead outside 1–30 is a bad field: 400, naming it. |
| @@ -1423,9 +1451,9 @@ export const routes: readonly Route[] = [ | ||
| 1423 | 1451 | }, |
| 1424 | 1452 | api: { |
| 1425 | 1453 | 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"] }, | |
| 1429 | 1457 | }, |
| 1430 | 1458 | }, |
| 1431 | 1459 | { |
src/sample.ts +6
| @@ -27,6 +27,8 @@ interface Sample { | ||
| 27 | 27 | readonly waived?: readonly string[]; |
| 28 | 28 | readonly custom?: readonly [string, number, PartyRole, string][]; |
| 29 | 29 | 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])[]; | |
| 30 | 32 | /** A reminder already sent, in the agent's own edited words: date kind, party role, moment, subject, body. */ |
| 31 | 33 | readonly sent?: readonly [string, PartyRole, "before" | "day_of", string, string]; |
| 32 | 34 | } |
| @@ -65,6 +67,7 @@ const SAMPLES: readonly Sample[] = [ | ||
| 65 | 67 | ["other_agent", "Alicia Moreno, Moreno & Co.", "[email protected]"], |
| 66 | 68 | ], |
| 67 | 69 | done: ["earnest"], |
| 70 | notes: [["inspection", "Inspector booked for Friday 9am; seller will leave the attic open"]], | |
| 68 | 71 | custom: [["HOA documents review ends", 1, "buyer", "Read the HOA budget, rules and minutes; object in writing if needed"]], |
| 69 | 72 | }, |
| 70 | 73 | { |
| @@ -81,6 +84,7 @@ const SAMPLES: readonly Sample[] = [ | ||
| 81 | 84 | done: ["earnest", "inspection", "title"], |
| 82 | 85 | custom: [["Repair credit agreed", 5, "seller", "Signed amendment for the roof repair credit"]], |
| 83 | 86 | moved: ["appraisal", 2, "Appraiser rescheduled — access to the property"], |
| 87 | notes: [["appraisal", "Appraisal ordered, AMC says Thursday"]], | |
| 84 | 88 | }, |
| 85 | 89 | { |
| 86 | 90 | address: "2210 Juniper Court", |
| @@ -235,6 +239,8 @@ function writeSamples(db: Database, on: string): void { | ||
| 235 | 239 | db.query("UPDATE deadline SET done_at = ?1 WHERE deal_id = ?2 AND kind = ?3").run(`${addDays(on, -1)}T17:00:00.000Z`, deal.id, kind); |
| 236 | 240 | for (const kind of s.waived ?? []) |
| 237 | 241 | 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); | |
| 238 | 244 | for (const [label, days, owes, what] of s.custom ?? []) |
| 239 | 245 | 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); |
| 240 | 246 | 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 () => | ||
| 183 | 183 | "reopen_deal", |
| 184 | 184 | "waive_date", |
| 185 | 185 | "move_date", |
| 186 | "set_date_note", | |
| 186 | 187 | "set_reminder_lead", |
| 187 | 188 | "amend_deal", |
| 188 | 189 | "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 | ||
| 763 | 763 | t.press("N"); |
| 764 | 764 | expect(lines(t).join("\n")).toContain("already on a business day"); |
| 765 | 765 | }); |
| 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 { | ||
| 46 | 46 | moveDeadline, |
| 47 | 47 | withConflicts, |
| 48 | 48 | removeDeadline, |
| 49 | setNote, | |
| 49 | 50 | setReminderLead, |
| 50 | 51 | removeParty, |
| 51 | 52 | sendReminder, |
| @@ -195,7 +196,7 @@ export function terminal( | ||
| 195 | 196 | |
| 196 | 197 | function onDate(key: string): boolean { |
| 197 | 198 | 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; | |
| 199 | 200 | if (row === undefined) { |
| 200 | 201 | said = "No date here."; |
| 201 | 202 | return true; |
| @@ -229,6 +230,11 @@ export function terminal( | ||
| 229 | 230 | return report(set, () => `${date.label}: ${remindsLine(set.ok ? set.value.lead_days : 0).toLowerCase()}.`); |
| 230 | 231 | }, |
| 231 | 232 | ); |
| 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 | }); | |
| 232 | 238 | if ((key === "o" || key === "\r") && view === "dates") { |
| 233 | 239 | view = "deal"; |
| 234 | 240 | dealId = deal.id; |
| @@ -658,7 +664,8 @@ export function terminal( | ||
| 658 | 664 | const moved = date.moves.length > 0 ? dim(` moved: ${date.moves.at(-1)!.reason}`) : ""; |
| 659 | 665 | const flag = date.nonBusinessDay === null ? "" : dim(` not a business day · next is ${spoken(date.nonBusinessDay.next)} (N moves it)`); |
| 660 | 666 | 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}`; | |
| 662 | 669 | }; |
| 663 | 670 | |
| 664 | 671 | function screen(): string[] { |
| @@ -825,8 +832,8 @@ export function terminal( | ||
| 825 | 832 | : view === "timeline" |
| 826 | 833 | ? "b back to the deal · d dates · q quit" |
| 827 | 834 | : 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`; | |
| 830 | 837 | lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys)); |
| 831 | 838 | } |
| 832 | 839 | return lines; |
new above
offline