Public: anyone can read this; the crew can change it.
Each deal has a client timeline: one printable page of its dates and who owes each, to hand to buyers or sellers, without the agent's controls #33
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/31-each-deal-has-a-client-timeline-one-prin → main 2 commits fork 3 threads · 3 unresolved
13 files
changed +324
−14
README.md +5
| @@ -85,6 +85,11 @@ for the same list; over MCP, an agent asks for the `this_week` tool. | ||
| 85 | 85 | 12. **Download the calendar file.** On a deal's page, tap Add to calendar. |
| 86 | 86 | You get a calendar file with every date of the deal and an alarm three days |
| 87 | 87 | before and the morning of, to open in your own calendar app. |
| 88 | 13. **Print the client timeline.** On a sample deal's page, tap Client | |
| 89 | timeline: its dates in order, who owes each and whether it is done, | |
| 90 | upcoming or overdue, with no controls. Print it with your browser's print | |
| 91 | to hand to a buyer or seller. In the terminal, open the deal with o and press | |
| 92 | t; over MCP, an agent asks for the `client_timeline` tool. | |
| 88 | 93 | |
| 89 | 94 | ## What is real, and what is not yet |
| 90 | 95 |
docs/TECHNICAL.md +8 −1
| @@ -36,13 +36,20 @@ sent until undone. Over the API: `POST /api/deals/:id/reminders/decline` and | ||
| 36 | 36 | `decline_reminder` and `undo_decline_reminder`; in the terminal, `n` then the |
| 37 | 37 | reason on the reminders list, and `u` to undo. Each is an update of the deal. |
| 38 | 38 | |
| 39 | `GET /deals/:id/timeline` is a deal's printable client timeline: its dates in | |
| 40 | order, who owes each, and Done, Upcoming or Overdue in words, with no forms, | |
| 41 | contacts or script (`src/pages/timeline.ts`, rows from `src/timeline.ts`). It | |
| 42 | reads like the deal page: `deal` read through `permit`, 401 signed out, 404 for | |
| 43 | no such deal. Over MCP it is `client_timeline`; in the terminal, `t` on an open | |
| 44 | deal (`b` goes back). Its print rules in `static/app.css` apply to that page only. | |
| 45 | ||
| 39 | 46 | A deal is **closed** when its Closing date is marked done (derived, no column; `closed` on `GET /api/deals` and `list_deals`). It leaves the clock for the Closed card, sends no reminders (`/tick`, `reminders_today`, the terminal `r` list), and the terminal date list shows its dates only after `h`. Reopening the Closing date reopens the deal. |
| 40 | 47 | |
| 41 | 48 | `POST /tick` answers the reminders that go out today and are not yet |
| 42 | 49 | marked sent, as JSON — call it each morning as a signed-in account (a |
| 43 | 50 | stranger gets 401; it sends nothing and changes nothing). `GET /deals/:id/ics` is a deal's calendar file. The JSON API is |
| 44 | 51 | `/api/deals`, described at `/openapi.json`; the same operations are MCP |
| 45 | tools at `POST /mcp` (`list_deals`, `get_deal`, `reminders_today`, `this_week`, | |
| 52 | tools at `POST /mcp` (`list_deals`, `get_deal`, `client_timeline`, `reminders_today`, `this_week`, | |
| 46 | 53 | `open_deal`, `add_date`, `add_party`, `edit_party`, `remove_party`, |
| 47 | 54 | `remove_date` — custom dates only — `remove_deal` — its author or an admin — |
| 48 | 55 | `mark_done` — with `done: false` to |
docs/design/areas/timeline.md added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | # Timeline | |
| 2 | ||
| 3 | Classes on `/deals/:id/timeline`, the page handed to a client. It prints portrait Letter/A4, black on white, with no header, footer or tools. | |
| 4 | ||
| 5 | - `.timeline` — the page's one section. | |
| 6 | - `.timeline-tools` — the hint to print and the link back; on screen only. | |
| 7 | - `body.timeline-page` — scopes every print rule to this page. | |
| 8 | - `.timeline-list` — the ordered list of dates, no markers. | |
| 9 | - `.timeline-row` — one date; never split across printed pages. | |
| 10 | - `.timeline-date`, `.timeline-label`, `.timeline-owner`, `.timeline-status` — its four facts; the status is words first, with a mark. |
src/mcp.ts +12
| @@ -29,6 +29,7 @@ import { | ||
| 29 | 29 | import { agent, title } from "./env.ts"; |
| 30 | 30 | import { dueOn } from "./reminders.ts"; |
| 31 | 31 | import { fields } from "./http.ts"; |
| 32 | import { timelineRows } from "./timeline.ts"; | |
| 32 | 33 | import { owner, thisWeek } from "./week.ts"; |
| 33 | 34 | import type { Who } from "./who.ts"; |
| 34 | 35 | |
| @@ -56,6 +57,17 @@ export const tools: readonly Tool[] = [ | ||
| 56 | 57 | inputSchema: { type: "object", properties: { id: { type: "integer" } }, required: ["id"] }, |
| 57 | 58 | run: (db, who, args) => getDeal(db, who, { id: Number(args.id) }), |
| 58 | 59 | }, |
| 60 | { | |
| 61 | name: "client_timeline", | |
| 62 | description: "One deal's dates as a client would receive them: address, the agent, and each date in due order with who owes it and whether it is Done, Upcoming or Overdue. No contacts, drafts or reasons.", | |
| 63 | inputSchema: { type: "object", properties: { id: { type: "integer" } }, required: ["id"] }, | |
| 64 | run: (db, who, args) => { | |
| 65 | const got = getDeal(db, who, { id: Number(args.id) }); | |
| 66 | if (!got.ok) return got; | |
| 67 | const dates = timelineRows(got.value, today()).map(({ label, due, role, name, status }) => ({ label, due, owed_by: { role, name: name ?? null }, status })); | |
| 68 | return { ok: true, value: { address: got.value.address, agent, dates } }; | |
| 69 | }, | |
| 70 | }, | |
| 59 | 71 | { |
| 60 | 72 | name: "reminders_today", |
| 61 | 73 | description: "The reminder drafts that go out today and have not been sent.", |
src/pages/deal.ts +1 −1
| @@ -110,7 +110,7 @@ export function dealPage(input: { | ||
| 110 | 110 | <h1>${escape(deal.address)}</h1> |
| 111 | 111 | <p class="summary">${deal.closed ? `<b>Closed on ${escape(spoken(closedOn(deal)))}</b> · ` : ""}Under contract ${escape(spoken(deal.contract_date))} · closes ${escape(spoken(deal.closing))}, ${escape(relative(deal.closing, on))}${deal.business_days ? " · business days" : ""}</p> |
| 112 | 112 | </div> |
| 113 | <a class="button button-quiet" href="${path}/ics" download>Add to calendar</a> | |
| 113 | <div class="row"><a class="button button-quiet" href="${path}/timeline">Client timeline</a> <a class="button button-quiet" href="${path}/ics" download>Add to calendar</a></div> | |
| 114 | 114 | </section> |
| 115 | 115 | <div id="deal" data-live="deal.changed"> |
| 116 | 116 | <section class="card"> |
src/pages/layout.ts +15 −7
| @@ -25,8 +25,12 @@ export function layout(input: { | ||
| 25 | 25 | path: string; |
| 26 | 26 | heading?: string; |
| 27 | 27 | notice?: string | undefined; |
| 28 | /** A page handed to someone outside the app: the brand only, no sign-in, footer or script. */ | |
| 29 | plain?: boolean; | |
| 30 | /** A class on <body>, for styles that belong to one page only. */ | |
| 31 | bodyClass?: string; | |
| 28 | 32 | }): string { |
| 29 | const { body, who, path, notice } = input; | |
| 33 | const { body, who, path, notice, plain = false, bodyClass } = input; | |
| 30 | 34 | const pageTitle = input.heading === undefined ? title : `${input.heading} · ${title}`; |
| 31 | 35 | const to = encodeURIComponent(path); |
| 32 | 36 | const door = |
| @@ -54,26 +58,30 @@ export function layout(input: { | ||
| 54 | 58 | <meta name="twitter:description" content="${escape(description)}"> |
| 55 | 59 | <link rel="stylesheet" href="${tokensHref}"> |
| 56 | 60 | <link rel="stylesheet" href="${asset("app.css")}"> |
| 57 | <script type="module" src="${asset("live.js")}"></script> | |
| 58 | <body> | |
| 61 | ${plain ? "" : `<script type="module" src="${asset("live.js")}"></script>`} | |
| 62 | <body${bodyClass === undefined ? "" : ` class="${escape(bodyClass)}"`}> | |
| 59 | 63 | <div class="page"> |
| 60 | 64 | <header class="head"> |
| 61 | 65 | <a class="brand" href="/"> |
| 62 | 66 | <span class="brand-mark" aria-hidden="true"></span> |
| 63 | 67 | <span><b>${escape(agent.name)}</b><small>${escape(agent.brokerage)}</small></span> |
| 64 | 68 | </a> |
| 65 | <nav class="row"> | |
| 69 | ${ | |
| 70 | plain | |
| 71 | ? "" | |
| 72 | : `<nav class="row"> | |
| 66 | 73 | ${env === "production" ? "" : `<span class="pill" data-env="${escape(env)}">${escape(where)}</span>`} |
| 67 | 74 | ${door} |
| 68 | </nav> | |
| 75 | </nav>` | |
| 76 | } | |
| 69 | 77 | </header> |
| 70 | 78 | <main>${body}</main> |
| 71 | <footer class="muted"> | |
| 79 | ${plain ? "" : `<footer class="muted"> | |
| 72 | 80 | <p>${escape(title)}${commit ? ` <span class="mono">${escape(commit)}</span>` : ""} — reminders here are drafted and marked sent; nothing is emailed or texted yet.</p> |
| 73 | 81 | ${ssh === undefined ? "<p>The terminal is off.</p>" : `<p>Terminal: <code>${escape(ssh)}</code></p>`} |
| 74 | 82 | <p>Also at <a href="/api/deals">/api/deals</a> (<a href="/openapi.json">described</a>), <code>POST /tick</code> and <code>POST /mcp</code>, with the same rules.</p> |
| 75 | 83 | <p>Something wrong? <a href="/__forge/report">Report a problem</a>, no account needed.</p> |
| 76 | </footer> | |
| 84 | </footer>`} | |
| 77 | 85 | </div> |
| 78 | 86 | ${notice === undefined ? "" : `<p class="toast" role="status">${escape(notice)}</p>`} |
| 79 | 87 | </body> |
src/pages/timeline.ts added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | /** | |
| 2 | * A deal's client timeline at `/deals/:id/timeline`: the page the agent | |
| 3 | * shows or prints for a buyer or seller. Its dates in due order, who owes | |
| 4 | * each and whether it is done, upcoming or overdue — and nothing internal: | |
| 5 | * no forms, drafts, reasons, audit or contacts. No script is sent. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { DealView } from "../deals.ts"; | |
| 9 | import { agent } from "../env.ts"; | |
| 10 | import { escape } from "../http.ts"; | |
| 11 | import { timelineRows } from "../timeline.ts"; | |
| 12 | import type { Who } from "../who.ts"; | |
| 13 | import { layout } from "./layout.ts"; | |
| 14 | ||
| 15 | export function timelinePage(input: { who: Who; deal: DealView; on: string }): string { | |
| 16 | const { who, deal, on } = input; | |
| 17 | const path = `/deals/${deal.id}/timeline`; | |
| 18 | const rows = timelineRows(deal, on) | |
| 19 | .map( | |
| 20 | (r) => `<li class="timeline-row" data-u="${r.urgency}"> | |
| 21 | <p class="timeline-date">${escape(r.spoken)}</p> | |
| 22 | <p class="timeline-label"><b>${escape(r.label)}</b></p> | |
| 23 | <p class="timeline-owner">${escape(r.role)}${r.name === undefined ? "" : ` · ${escape(r.name)}`}</p> | |
| 24 | <p class="timeline-status"><span aria-hidden="true">${r.mark}</span> ${r.status}</p> | |
| 25 | </li>`, | |
| 26 | ) | |
| 27 | .join(""); | |
| 28 | const body = `<p class="crumb timeline-tools"><a href="/deals/${deal.id}">← Back to the deal</a> · To print, use your browser's print (Ctrl/Cmd+P)</p> | |
| 29 | <section class="timeline"> | |
| 30 | <h1>${escape(deal.address)}</h1> | |
| 31 | <p class="summary">Key dates, prepared by ${escape(agent.name)}, ${escape(agent.brokerage)}</p> | |
| 32 | <ol class="timeline-list">${rows}</ol> | |
| 33 | </section>`; | |
| 34 | return layout({ body, who, path, heading: `Timeline · ${deal.address}`, plain: true, bodyClass: "timeline-page" }); | |
| 35 | } |
src/routes.ts +20
| @@ -61,6 +61,7 @@ import { rpc } from "./mcp.ts"; | ||
| 61 | 61 | import { clock } from "./pages/clock.ts"; |
| 62 | 62 | import { dealPage, newDealPage } from "./pages/deal.ts"; |
| 63 | 63 | import { refusedPage } from "./pages/refused.ts"; |
| 64 | import { timelinePage } from "./pages/timeline.ts"; | |
| 64 | 65 | import { dueOn } from "./reminders.ts"; |
| 65 | 66 | import { tokensCss } from "./tokens.ts"; |
| 66 | 67 | import type { Who } from "./who.ts"; |
| @@ -355,6 +356,25 @@ export const routes: readonly Route[] = [ | ||
| 355 | 356 | return html(dealPage({ who: c.who, deal: found.value, on: today(), notice }), 200, clear); |
| 356 | 357 | }, |
| 357 | 358 | }, |
| 359 | { | |
| 360 | method: "GET", | |
| 361 | path: "/deals/:id/timeline", | |
| 362 | handle: (c) => { | |
| 363 | const found = getDeal(c.db, c.who, { id: Number(c.params.id) }); | |
| 364 | if (!found.ok) | |
| 365 | return html( | |
| 366 | refusedPage({ | |
| 367 | who: c.who, | |
| 368 | path: c.url.pathname, | |
| 369 | heading: found.error === "not_found" || found.error === "invalid" ? "No such deal" : "A deal", | |
| 370 | error: found.error, | |
| 371 | message: found.message, | |
| 372 | }), | |
| 373 | STATUS[found.error], | |
| 374 | ); | |
| 375 | return html(timelinePage({ who: c.who, deal: found.value, on: today() })); | |
| 376 | }, | |
| 377 | }, | |
| 358 | 378 | { |
| 359 | 379 | method: "GET", |
| 360 | 380 | path: "/deals/:id/ics", |
src/server.test.ts +18
| @@ -156,6 +156,7 @@ test("the MCP server lists the tools and calls them as the caller", async () => | ||
| 156 | 156 | expect(listed.result.tools.map((t: { name: string }) => t.name)).toEqual([ |
| 157 | 157 | "list_deals", |
| 158 | 158 | "get_deal", |
| 159 | "client_timeline", | |
| 159 | 160 | "reminders_today", |
| 160 | 161 | "this_week", |
| 161 | 162 | "mark_done", |
| @@ -431,10 +432,27 @@ test("a deal's page, its calendar file, and a 404 for one that is not there", as | ||
| 431 | 432 | expect(guestPage).toContain(`/__forge/signin?to=${encodeURIComponent(`/deals/${deal.id}`)}`); |
| 432 | 433 | expect(guestPage).not.toContain(deal.address.replace("&", "&")); |
| 433 | 434 | expect((await fetch(`${base}/deals/${deal.id}/ics`)).status).toBe(401); |
| 435 | const guestTimeline = await fetch(`${base}/deals/${deal.id}/timeline`); | |
| 436 | expect(guestTimeline.status).toBe(401); | |
| 437 | expect(await guestTimeline.text()).not.toContain(deal.address.replace("&", "&")); | |
| 438 | const timeline = await api(`/deals/${deal.id}/timeline`, {}, alice); | |
| 439 | expect(timeline.status).toBe(200); | |
| 440 | const timelineHtml = await timeline.text(); | |
| 441 | expect(timelineHtml).toContain(deal.address.replace("&", "&")); | |
| 442 | expect(timelineHtml).not.toContain("live.js"); | |
| 443 | expect(timelineHtml).not.toContain("<footer"); | |
| 444 | expect(timelineHtml).not.toContain("<nav"); | |
| 445 | expect(timelineHtml).toContain('<body class="timeline-page">'); | |
| 446 | const tool = (await rpc({ jsonrpc: "2.0", id: 11, method: "tools/call", params: { name: "client_timeline", arguments: { id: deal.id } } }, alice)).result; | |
| 447 | expect(JSON.parse(tool.content[0].text).dates[0]).toHaveProperty("owed_by"); | |
| 448 | expect(JSON.stringify(tool)).not.toContain("contact"); | |
| 449 | expect((await api(`/deals/999999/timeline`, {}, alice)).status).toBe(404); | |
| 450 | expect(await (await api(`/deals/${deal.id}`, {}, alice)).text()).toContain("<footer"); | |
| 434 | 451 | expect((await fetch(`${base}/api/deals`)).status).toBe(401); |
| 435 | 452 | const page = await (await api(`/deals/${deal.id}`, {}, alice)).text(); |
| 436 | 453 | expect(page).toContain(deal.address.replace("&", "&")); |
| 437 | 454 | expect(page).toContain(`href="/deals/${deal.id}/ics"`); |
| 455 | expect(page).toContain(`href="/deals/${deal.id}/timeline"`); | |
| 438 | 456 | expect(page).toContain('popover id="sheet-'); |
| 439 | 457 | const ics = await api(`/deals/${deal.id}/ics`, {}, alice); |
| 440 | 458 | expect(ics.headers.get("content-type")).toContain("text/calendar"); |
src/terminal.ts +21 −5
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * dates every open date of every deal, soonest first (h shows done ones) |
| 7 | 7 | * week the open dates overdue or due in the next seven days, by day |
| 8 | 8 | * reminders what goes out today; enter reads a draft, e edits its words, s sends it |
| 9 | * timeline a deal's dates as a client would get them (t on a deal) | |
| 9 | 10 | * deal one deal's dates and parties; a adds a date, p a party, D removes it |
| 10 | 11 | * |
| 11 | 12 | * On a date (dates or deal view): x marks it done, u reopens it, m moves it |
| @@ -15,6 +16,7 @@ | ||
| 15 | 16 | */ |
| 16 | 17 | |
| 17 | 18 | import type { Database } from "bun:sqlite"; |
| 19 | import { timelineRows } from "./timeline.ts"; | |
| 18 | 20 | import { isDate, relative, spoken, today, urgency, type Urgency } from "./dates.ts"; |
| 19 | 21 | import { |
| 20 | 22 | addDeadline, |
| @@ -54,7 +56,7 @@ const bold = (s: string): string => `${esc}1m${s}${esc}0m`; | ||
| 54 | 56 | const COLOUR: Readonly<Record<Urgency, string>> = { overdue: "31", soon: "33", later: "36", done: "2" }; |
| 55 | 57 | const tint = (u: Urgency, s: string): string => `${esc}${COLOUR[u]}m${s}${esc}0m`; |
| 56 | 58 | |
| 57 | type View = "dates" | "week" | "reminders" | "deal" | "messages"; | |
| 59 | type View = "dates" | "week" | "reminders" | "deal" | "messages" | "timeline"; | |
| 58 | 60 | interface Row { |
| 59 | 61 | readonly deal: DealView; |
| 60 | 62 | readonly date: DeadlineView; |
| @@ -337,12 +339,15 @@ export function terminal( | ||
| 337 | 339 | } |
| 338 | 340 | if (key === "j") cursor = Math.min(cursor + 1, Math.max(0, rowCount() - 1)); |
| 339 | 341 | else if (key === "k") cursor = Math.max(cursor - 1, 0); |
| 340 | else if (view === "messages" && (key === "b" || key === "\x1b")) { | |
| 342 | else if ((view === "messages" || view === "timeline") && (key === "b" || key === "\x1b")) { | |
| 341 | 343 | view = "deal"; |
| 342 | 344 | cursor = 0; |
| 343 | 345 | reading = undefined; |
| 344 | 346 | } else if (view === "messages" && key === "\r") reading = reading === cursor ? undefined : cursor; |
| 345 | else if (view === "deal" && key === "s") { | |
| 347 | else if (view === "deal" && key === "t") { | |
| 348 | view = "timeline"; | |
| 349 | cursor = 0; | |
| 350 | } else if (view === "deal" && key === "s") { | |
| 346 | 351 | view = "messages"; |
| 347 | 352 | cursor = 0; |
| 348 | 353 | reading = undefined; |
| @@ -379,7 +384,7 @@ export function terminal( | ||
| 379 | 384 | showDone = !showDone; |
| 380 | 385 | cursor = 0; |
| 381 | 386 | } else if (view === "reminders") onReminder(key); |
| 382 | else if (view === "messages") return; | |
| 387 | else if (view === "messages" || view === "timeline") return; | |
| 383 | 388 | else if (!(view === "deal" && onDeal(key))) onDate(key); |
| 384 | 389 | cursor = Math.min(cursor, Math.max(0, rowCount() - 1)); |
| 385 | 390 | } |
| @@ -443,6 +448,15 @@ export function terminal( | ||
| 443 | 448 | if (reading === i) lines.push("", ` ${bold(m.subject === "" ? "(words not kept)" : m.subject)}`, ...m.body.split("\n").map((l) => ` ${l}`), ""); |
| 444 | 449 | }); |
| 445 | 450 | } |
| 451 | } else if (view === "timeline") { | |
| 452 | const deal = openDeal(); | |
| 453 | if (deal === undefined) lines.push(dim("That deal is gone.")); | |
| 454 | else { | |
| 455 | lines.push(bold(`Client timeline — ${deal.address}`), dim(`${context.agent.name}, ${context.agent.brokerage}`), ""); | |
| 456 | timelineRows(deal, day).forEach((r) => | |
| 457 | lines.push(` ${tint(r.urgency, `${r.spoken.padEnd(16)} ${r.status.padEnd(9)}`)} ${r.label} · ${r.name === undefined ? r.role : `${r.role}: ${r.name}`}`), | |
| 458 | ); | |
| 459 | } | |
| 446 | 460 | } else if (view === "deal") { |
| 447 | 461 | const deal = openDeal(); |
| 448 | 462 | if (deal === undefined) lines.push(dim("That deal is gone.")); |
| @@ -478,8 +492,10 @@ export function terminal( | ||
| 478 | 492 | ? "j/k move · enter read · e edit · s send · n don't send · u undo · d dates · q quit" |
| 479 | 493 | : view === "messages" |
| 480 | 494 | ? "j/k move · enter read · b back to the deal · d dates · q quit" |
| 495 | : view === "timeline" | |
| 496 | ? "b back to the deal · d dates · q quit" | |
| 481 | 497 | : view === "deal" |
| 482 | ? "j/k move · s messages · x done · u reopen · m move · a add date · p add party · e edit party · X remove date/party · D remove deal · b back · q quit" | |
| 498 | ? "j/k move · t client timeline · s messages · x done · u reopen · m move · a add date · p add party · e edit party · X remove date/party · D remove deal · b back · q quit" | |
| 483 | 499 | : `j/k move · x done · u reopen · m move · o open deal · n new deal · c check dates · h ${showDone ? "hide" : "show"} done · w this week · r reminders · q quit`; |
| 484 | 500 | lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys)); |
| 485 | 501 | } |
src/timeline.test.ts added +80
| @@ -0,0 +1,80 @@ | ||
| 1 | /** The client timeline: the deal's dates and owners, and nothing internal. */ | |
| 2 | import { 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 { addDeadline, addParty, createDeal, getDeal, markDone, removeDeadline } from "./deals.ts"; | |
| 7 | import { terminal } from "./terminal.ts"; | |
| 8 | import { openDb } from "./db.ts"; | |
| 9 | import { timelinePage } from "./pages/timeline.ts"; | |
| 10 | import type { Who } from "./who.ts"; | |
| 11 | ||
| 12 | const db = openDb(mkdtempSync(join(tmpdir(), "app-timeline-"))); | |
| 13 | const alice: Who = { role: "user", id: "u1", name: "alice" }; | |
| 14 | ||
| 15 | const made = createDeal(db, alice, { address: "9 <b>Oak</b> Rd", buyer: "Ann Buyer", seller: "Sam Seller", contractDate: "2026-10-01", closingDate: "2026-11-06" }); | |
| 16 | if (!made.ok) throw new Error(made.message); | |
| 17 | const id = made.value.id; | |
| 18 | addParty(db, alice, { dealId: id, role: "lender", name: "Lena Lender", contact: "[email protected]" }); | |
| 19 | addParty(db, alice, { dealId: id, role: "buyer", name: "Ann Buyer", contact: "[email protected]" }); | |
| 20 | const keep = addDeadline(db, alice, { dealId: id, label: "HOA review ends", due: "2026-10-20", owes: "buyer", what: "" }); | |
| 21 | const drop = addDeadline(db, alice, { dealId: id, label: "Gone repair date", due: "2026-10-22", owes: "seller", what: "" }); | |
| 22 | if (!keep.ok || !drop.ok) throw new Error("setup"); | |
| 23 | removeDeadline(db, alice, { dealId: id, id: drop.value.id }); | |
| 24 | const inspection = getDeal(db, alice, { id }); | |
| 25 | if (!inspection.ok) throw new Error("setup"); | |
| 26 | markDone(db, alice, { id: inspection.value.deadlines.find((d) => d.kind !== "closing")!.id, done: true }); | |
| 27 | ||
| 28 | const page = (on: string): string => { | |
| 29 | const deal = getDeal(db, alice, { id }); | |
| 30 | if (!deal.ok) throw new Error(deal.message); | |
| 31 | return timelinePage({ who: alice, deal: deal.value, on }); | |
| 32 | }; | |
| 33 | ||
| 34 | test("lists the dates in due order with owners and status words", () => { | |
| 35 | const html = page("2026-10-25"); | |
| 36 | const dates = [...html.matchAll(/timeline-label"><b>([^<]*)</g)].map((m) => m[1]); | |
| 37 | expect(dates).toContain("HOA review ends"); | |
| 38 | expect(html.indexOf("HOA review ends")).toBeLessThan(html.indexOf("Closing")); | |
| 39 | expect(html).toContain("Buyer · Ann Buyer"); | |
| 40 | expect(html).toContain("Overdue"); | |
| 41 | expect(html).toContain("Done"); | |
| 42 | expect(html).toContain("Upcoming"); | |
| 43 | expect(html).toContain("Dana Whitfield"); | |
| 44 | }); | |
| 45 | ||
| 46 | test("has no forms, scripts, contacts or removed dates, and escapes the address", () => { | |
| 47 | const html = page("2026-10-25"); | |
| 48 | expect(html).not.toContain("<form"); | |
| 49 | expect(html).not.toContain("<script"); | |
| 50 | expect(html).not.toContain("<button"); | |
| 51 | expect(html).not.toContain("[email protected]"); | |
| 52 | expect(html).not.toContain("[email protected]"); | |
| 53 | expect(html).not.toContain("Gone repair date"); | |
| 54 | expect(html).toContain("9 <b>Oak</b> Rd"); | |
| 55 | expect(html).not.toContain("<b>Oak</b>"); | |
| 56 | }); | |
| 57 | ||
| 58 | test("the print rules are scoped to the timeline page", async () => { | |
| 59 | const css = await Bun.file(join(import.meta.dir, "..", "static", "app.css")).text(); | |
| 60 | const print = css.slice(css.indexOf("@media print")); | |
| 61 | const selectors = [...print.matchAll(/^\s*([^{}@\n]+)\{/gm)].map((m) => m[1]!.trim()); | |
| 62 | expect(selectors.length).toBeGreaterThan(0); | |
| 63 | for (const sel of selectors) for (const part of sel.split(",")) expect(part.trim()).toStartWith(".timeline-page"); | |
| 64 | }); | |
| 65 | ||
| 66 | test("the terminal shows the same dates and owners for the open deal, ", () => { | |
| 67 | const t = terminal(db, alice, { title: "deal-clock", where: "test", agent: { name: "Dana", brokerage: "HP" }, on: () => "2026-10-25" }); | |
| 68 | const row = (): string => t.screen().join("\n").split("\n").find((l) => l.startsWith("▸")) ?? ""; | |
| 69 | for (let i = 0; i < 300 && !row().includes("HOA review ends"); i++) t.press("j"); | |
| 70 | t.press("o"); | |
| 71 | t.press("t"); | |
| 72 | const screen = t.screen().join("\n").replace(/\x1b\[[0-9;]*m/g, ""); | |
| 73 | expect(screen).toContain("Client timeline"); | |
| 74 | expect(screen).toContain("HOA review ends"); | |
| 75 | expect(screen).toContain("Buyer: Ann Buyer"); | |
| 76 | expect(screen).toContain("Overdue"); | |
| 77 | expect(screen).not.toContain("[email protected]"); | |
| 78 | t.press("b"); | |
| 79 | expect(t.screen().join("\n")).not.toContain("Client timeline"); | |
| 80 | }); |
src/timeline.ts added +42
| @@ -0,0 +1,42 @@ | ||
| 1 | /** | |
| 2 | * What a client is told about a deal's dates: each in due order with who owes | |
| 3 | * it and whether it is done, upcoming or overdue. Plain data from a deal and | |
| 4 | * a day, shared by the page, the terminal and the MCP tool; it holds nothing | |
| 5 | * internal — no notes, drafts, reasons or contacts. | |
| 6 | */ | |
| 7 | ||
| 8 | import { spoken, urgency, type Urgency } from "./dates.ts"; | |
| 9 | import type { DealView } from "./deals.ts"; | |
| 10 | import { owner } from "./week.ts"; | |
| 11 | ||
| 12 | export type TimelineStatus = "Done" | "Upcoming" | "Overdue"; | |
| 13 | ||
| 14 | /** Words first, so black and white reads the same as colour; the mark is only a helper. */ | |
| 15 | const STATUS: Readonly<Record<Urgency, { mark: string; word: TimelineStatus }>> = { | |
| 16 | done: { mark: "✓", word: "Done" }, | |
| 17 | overdue: { mark: "!", word: "Overdue" }, | |
| 18 | soon: { mark: "○", word: "Upcoming" }, | |
| 19 | later: { mark: "○", word: "Upcoming" }, | |
| 20 | }; | |
| 21 | ||
| 22 | export interface TimelineRow { | |
| 23 | readonly label: string; | |
| 24 | /** ISO date. */ | |
| 25 | readonly due: string; | |
| 26 | /** "Thu, Oct 15, 2026". */ | |
| 27 | readonly spoken: string; | |
| 28 | /** The role that owes it, and the deal's party in that role if it has one. */ | |
| 29 | readonly role: string; | |
| 30 | readonly name: string | undefined; | |
| 31 | readonly status: TimelineStatus; | |
| 32 | readonly mark: string; | |
| 33 | readonly urgency: Urgency; | |
| 34 | } | |
| 35 | ||
| 36 | export function timelineRows(deal: DealView, on: string): TimelineRow[] { | |
| 37 | return deal.deadlines.map((d) => { | |
| 38 | const u = urgency(d.due, on, d.done_at !== null); | |
| 39 | const { name, role } = owner(deal, d); | |
| 40 | return { label: d.label, due: d.due, spoken: spoken(d.due), role, name, status: STATUS[u].word, mark: STATUS[u].mark, urgency: u }; | |
| 41 | }); | |
| 42 | } |
static/app.css +57
| @@ -781,3 +781,60 @@ textarea.input { | ||
| 781 | 781 | .week-row .badge { |
| 782 | 782 | flex: none; |
| 783 | 783 | } |
| 784 | ||
| 785 | /* The client timeline. */ | |
| 786 | .timeline-list { | |
| 787 | list-style: none; | |
| 788 | margin: var() 0 0; | |
| 789 | padding: 0; | |
| 790 | } | |
| 791 | .timeline-row { | |
| 792 | display: grid; | |
| 793 | grid-template-columns: 11rem 1fr 14rem 7rem; | |
| 794 | gap: var() var(); | |
| 795 | padding: var() 0; | |
| 796 | border-top: 1px solid var(); | |
| 797 | } | |
| 798 | .timeline-row p { | |
| 799 | margin: 0; | |
| 800 | } | |
| 801 | .timeline-status { | |
| 802 | font-weight: 650; | |
| 803 | } | |
| 804 | .timeline-row[data-u="overdue"] .timeline-status { | |
| 805 | color: var(); | |
| 806 | } | |
| 807 | @media (max-width: 40rem) { | |
| 808 | .timeline-row { | |
| 809 | grid-template-columns: 1fr; | |
| 810 | } | |
| 811 | } | |
| 812 | ||
| 813 | /* On paper: only the client timeline changes — black on white, no tools, no row split. */ | |
| 814 | @media print { | |
| 815 | .timeline-page { | |
| 816 | background: white; | |
| 817 | color: black; | |
| 818 | } | |
| 819 | .timeline-page .head, | |
| 820 | .timeline-page footer, | |
| 821 | .timeline-page .timeline-tools { | |
| 822 | display: none; | |
| 823 | } | |
| 824 | .timeline-page .page { | |
| 825 | max-width: none; | |
outdated
These selectors hide controls on every page when printed. Scope them under the timeline page only. |
||
| 826 | padding: 0; | |
| 827 | } | |
| 828 | .timeline-page .timeline-row { | |
| 829 | grid-template-columns: 30% 1fr 25% 15%; | |
| 830 | break-inside: avoid; | |
| 831 | border-color: black; | |
| 832 | color: black; | |
| 833 | } | |
| 834 | .timeline-page .timeline-row[data-u="overdue"] .timeline-status { | |
| 835 | color: black; | |
| 836 | } | |
| 837 | @page { | |
| 838 | margin: 15mm; | |
| 839 | } | |
| 840 | } |
new above
offline
The same data must be reachable from the terminal and MCP (tool with the same getDeal gate); only the web door has it now.