Public: anyone can read this; the crew can change it.
A People page lists each person on the agent's deals with every open date they owe, across all deals, soonest first, so one call covers them all #49
Check · Review · Land · Live done — Landed and live in production.
mason/deal-clock:mason/30-a-people-page-lists-each-person-on-the-a → main 3 commits fork
16 files
changed +391
−7
README.md +5
| @@ -22,6 +22,11 @@ address, who owes it and how urgent it is; tap a row to open its sheet. It | ||
| 22 | 22 | reads well on a phone, with no sideways scrolling. In the terminal, press w |
| 23 | 23 | for the same list; over MCP, an agent asks for the `this_week` tool. |
| 24 | 24 | |
| 25 | Before calling a lender or an inspector, open **People** in the header: each | |
| 26 | person on your deals appears once, with every open date they owe across all | |
| 27 | deals, soonest first (try Priya Nair, who works both 1418 Alder Lane and 9 Orchard | |
| 28 | Row). In the terminal, press P; over MCP, ask for `list_people`. | |
| 29 | ||
| 25 | 30 | To find a deal, type part of its address, or of a buyer's, seller's or other |
| 26 | 31 | party's name, phone or email, into **Find a deal** above the clock and press |
| 27 | 32 | Find (try `harbor`). The clock, This week and today's reminders narrow to the |
contract/openapi.json +81
| @@ -203,6 +203,87 @@ | ||
| 203 | 203 | } |
| 204 | 204 | } |
| 205 | 205 | }, |
| 206 | "/api/people": { | |
| 207 | "get": { | |
| 208 | "summary": "Each person on your deals once (parties with the same contact are one), with their roles and every open date they owe across deals, soonest first; people who owe nothing open come last.", | |
| 209 | "operationId": "getApiPeople", | |
| 210 | "responses": { | |
| 211 | "200": { | |
| 212 | "description": "Each person on your deals once (parties with the same contact are one), with their roles and every open date they owe across deals, soonest first; people who owe nothing open come last.", | |
| 213 | "content": { | |
| 214 | "application/json": { | |
| 215 | "schema": { | |
| 216 | "type": "array", | |
| 217 | "items": { | |
| 218 | "type": "object", | |
| 219 | "properties": { | |
| 220 | "name": { | |
| 221 | "type": "string" | |
| 222 | }, | |
| 223 | "contact": { | |
| 224 | "type": "string" | |
| 225 | }, | |
| 226 | "roles": { | |
| 227 | "type": "array", | |
| 228 | "items": { | |
| 229 | "type": "string" | |
| 230 | } | |
| 231 | }, | |
| 232 | "owes": { | |
| 233 | "type": "array", | |
| 234 | "items": { | |
| 235 | "type": "object", | |
| 236 | "properties": { | |
| 237 | "deal_id": { | |
| 238 | "type": "integer" | |
| 239 | }, | |
| 240 | "address": { | |
| 241 | "type": "string" | |
| 242 | }, | |
| 243 | "deadline_id": { | |
| 244 | "type": "integer" | |
| 245 | }, | |
| 246 | "label": { | |
| 247 | "type": "string" | |
| 248 | }, | |
| 249 | "due": { | |
| 250 | "type": "string", | |
| 251 | "format": "date" | |
| 252 | }, | |
| 253 | "urgency": { | |
| 254 | "enum": [ | |
| 255 | "overdue", | |
| 256 | "soon", | |
| 257 | "later" | |
| 258 | ] | |
| 259 | } | |
| 260 | } | |
| 261 | } | |
| 262 | } | |
| 263 | } | |
| 264 | } | |
| 265 | } | |
| 266 | } | |
| 267 | } | |
| 268 | }, | |
| 269 | "default": { | |
| 270 | "description": "{ error, message }: why not", | |
| 271 | "content": { | |
| 272 | "application/json": { | |
| 273 | "schema": { | |
| 274 | "$ref": "#/components/schemas/Error" | |
| 275 | } | |
| 276 | } | |
| 277 | } | |
| 278 | } | |
| 279 | }, | |
| 280 | "x-contract": { | |
| 281 | "resource": "deal", | |
| 282 | "verb": "list", | |
| 283 | "least": "user" | |
| 284 | } | |
| 285 | } | |
| 286 | }, | |
| 206 | 287 | "/api/deals/{id}": { |
| 207 | 288 | "get": { |
| 208 | 289 | "summary": "One deal.", |
docs/TECHNICAL.md +3 −1
| @@ -45,13 +45,15 @@ reads like the deal page: `deal` read through `permit`, 401 signed out, 404 for | ||
| 45 | 45 | no such deal. Over MCP it is `client_timeline`; in the terminal, `t` on an open |
| 46 | 46 | deal (`b` goes back). Its print rules in `static/app.css` apply to that page only. |
| 47 | 47 | |
| 48 | `GET /people` (and `GET /api/people`, described in `openapi.json` under the `deal` list cell) groups every party on the deals the viewer may list into people — parties with the same contact, trimmed and case-insensitive, are one, under the newest name — each with the open dates they owe (`src/people.ts`, pure). Dates of a closed deal are not listed. The terminal's `P` view shows the same. | |
| 49 | ||
| 48 | 50 | 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. |
| 49 | 51 | |
| 50 | 52 | `POST /tick` answers the reminders that go out today and are not yet |
| 51 | 53 | marked sent, as JSON — call it each morning as a signed-in account (a |
| 52 | 54 | stranger gets 401; it sends nothing and changes nothing). `GET /deals/:id/ics` is a deal's calendar file. The JSON API is |
| 53 | 55 | `/api/deals`, described at `/openapi.json`; the same operations are MCP |
| 54 | tools at `POST /mcp` (`list_deals`, `get_deal`, `client_timeline`, `reminders_today`, `this_week`, | |
| 56 | tools at `POST /mcp` (`list_deals`, `get_deal`, `client_timeline`, `reminders_today`, `this_week`, `list_people`, | |
| 55 | 57 | `open_deal`, `add_date`, `update_address`, `add_party`, `edit_party`, `remove_party`, |
| 56 | 58 | `remove_date` — custom dates only — `remove_deal` — its author or an admin — |
| 57 | 59 | `mark_done` — with `done: false` to |
docs/design/areas/people.md added +5
| @@ -0,0 +1,5 @@ | ||
| 1 | # People | |
| 2 | ||
| 3 | Classes on `/people`, the list of everyone on the agent's deals with the dates they owe. Rows reuse `.week-list`, `.week-row` and `.badge`. | |
| 4 | ||
| 5 | - `.person` — one person's card: name, roles and contact, then their open dates or "Nothing open". |
src/contract.test.ts +9
| @@ -136,3 +136,12 @@ test("restoring the samples answers as the table says for the cells it exercises | ||
| 136 | 136 | expect(mayRestore({ role: "admin", id: "a", name: "a" }).ok).toBe(true); |
| 137 | 137 | expect(mayRestore({ role: "user", id: "u", name: "u" }).ok).toBe(false); |
| 138 | 138 | }); |
| 139 | ||
| 140 | test("People, at the page, GET /api/people and list_people, answers as deal list says, as every identity", () => { | |
| 141 | for (const identity of identities(contract)) { | |
| 142 | const who = whoIs(identity); | |
| 143 | const said = `people as ${identity}`; | |
| 144 | const listed = listDeals(db, who); | |
| 145 | expect([said, listed.ok]).toEqual([said, permit(who, "deal", "list") !== "no"]); | |
| 146 | } | |
| 147 | }); |
src/mcp.ts +10
| @@ -31,6 +31,7 @@ import { agent, title } from "./env.ts"; | ||
| 31 | 31 | import { dueOn } from "./reminders.ts"; |
| 32 | 32 | import { FIND_REFUSAL, find, query } from "./find.ts"; |
| 33 | 33 | import { fields } from "./http.ts"; |
| 34 | import { people } from "./people.ts"; | |
| 34 | 35 | import { timelineRows } from "./timeline.ts"; |
| 35 | 36 | import { owner, thisWeek } from "./week.ts"; |
| 36 | 37 | import type { Who } from "./who.ts"; |
| @@ -103,6 +104,15 @@ export const tools: readonly Tool[] = [ | ||
| 103 | 104 | : deals; |
| 104 | 105 | }, |
| 105 | 106 | }, |
| 107 | { | |
| 108 | name: "list_people", | |
| 109 | description: "Each person on the deals once (parties with the same contact are one) with their roles and every open date they owe across deals, soonest first; people who owe nothing open come last.", | |
| 110 | inputSchema: { type: "object", properties: {} }, | |
| 111 | run: (db, who) => { | |
| 112 | const deals = listDeals(db, who); | |
| 113 | return deals.ok ? { ok: true, value: people(deals.value, today()) } : deals; | |
| 114 | }, | |
| 115 | }, | |
| 106 | 116 | { |
| 107 | 117 | name: "mark_done", |
| 108 | 118 | description: "Mark a date done (or reopen it with done: false).", |
src/openapi.ts +2 −2
| @@ -42,7 +42,7 @@ export function openapi(): Record<string, unknown> { | ||
| 42 | 42 | const paths: Record<string, Record<string, unknown>> = {}; |
| 43 | 43 | for (const route of routes) { |
| 44 | 44 | if (route.api === undefined) continue; |
| 45 | const { summary, body, answer, status, query } = route.api; | |
| 45 | const { summary, body, answer, status, query, cell } = route.api; | |
| 46 | 46 | const path = route.path.replace(/:(\w+)/g, "{$1}"); |
| 47 | 47 | const params = [...route.path.matchAll(/:(\w+)/g)].map(([, name]) => ({ |
| 48 | 48 | name, |
| @@ -50,7 +50,7 @@ export function openapi(): Record<string, unknown> { | ||
| 50 | 50 | required: true, |
| 51 | 51 | schema: { type: "integer" }, |
| 52 | 52 | })); |
| 53 | const door = doorOf(route.method, route.path.replace(/:\w+/g, "0")); | |
| 53 | const door = doorOf(route.method, route.path.replace(/:\w+/g, "0")) ?? cell; | |
| 54 | 54 | const least = |
| 55 | 55 | door === undefined |
| 56 | 56 | ? undefined |
src/pages/layout.ts +1
| @@ -75,6 +75,7 @@ ${plain || input.live === false ? "" : `<script type="module" src="${asset("live | ||
| 75 | 75 | ? "" |
| 76 | 76 | : `<nav class="row"> |
| 77 | 77 | ${env === "production" ? "" : `<span class="pill" data-env="${escape(env)}">${escape(where)}</span>`} |
| 78 | ${who.role === "anon" ? "" : `<a class="button button-quiet" href="/">Clock</a> <a class="button button-quiet" href="/people">People</a>`} | |
| 78 | 79 | ${door} |
| 79 | 80 | </nav>` |
| 80 | 81 | } |
src/pages/people.ts added +29
| @@ -0,0 +1,29 @@ | ||
| 1 | /** | |
| 2 | * Who owes what, at `/people`: each person on the agent's deals once, with | |
| 3 | * every open date they owe across deals, soonest first. Server-rendered, no | |
| 4 | * script; a row opens its deal. | |
| 5 | */ | |
| 6 | ||
| 7 | import { relative, spoken } from "../dates.ts"; | |
| 8 | import { escape } from "../http.ts"; | |
| 9 | import type { Person } from "../people.ts"; | |
| 10 | import type { Who } from "../who.ts"; | |
| 11 | import { layout } from "./layout.ts"; | |
| 12 | import { URGENCY_LABEL } from "./sheet.ts"; | |
| 13 | ||
| 14 | const owedRow = (o: Person["owes"][number], on: string): string => | |
| 15 | `<li><a class="week-row" href="/deals/${o.deal_id}"><span class="week-what"><b>${escape(o.label)}</b><small class="muted">${escape(o.address)} · ${escape(spoken(o.due))} · ${escape(relative(o.due, on))}</small></span><span class="badge" data-u="${o.urgency}">${URGENCY_LABEL[o.urgency]}</span></a></li>`; | |
| 16 | ||
| 17 | const person = (p: Person, on: string): string => `<section class="card person"> | |
| 18 | <h2>${escape(p.name)}</h2> | |
| 19 | <p class="muted">${escape(p.roles.join(", "))}${p.contact === "" ? "" : ` · ${escape(p.contact)}`}</p> | |
| 20 | ${p.owes.length === 0 ? `<p class="muted">Nothing open</p>` : `<ul class="week-list">${p.owes.map((o) => owedRow(o, on)).join("")}</ul>`} | |
| 21 | </section>`; | |
| 22 | ||
| 23 | export function peoplePage(input: { who: Who; people: readonly Person[]; on: string }): string { | |
| 24 | const { who, people, on } = input; | |
| 25 | const body = `<h1>People</h1> | |
| 26 | <p class="summary">Everyone on your deals, with every open date they owe, soonest first.</p> | |
| 27 | ${people.length === 0 ? `<p class="muted">No one yet: add a deal and its parties.</p>` : people.map((p) => person(p, on)).join("")}`; | |
| 28 | return layout({ body, who, path: "/people", heading: "People", live: false }); | |
| 29 | } |
src/people.test.ts added +45
| @@ -0,0 +1,45 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import type { DealView } from "./deals.ts"; | |
| 3 | import { people, personKey } from "./people.ts"; | |
| 4 | ||
| 5 | const on = "2026-10-10"; | |
| 6 | const deal = (id: number, address: string, parties: [number, string, string, string][], dates: [number, string, string, string, string | null][], closed = false): DealView => | |
| 7 | ({ | |
| 8 | id, | |
| 9 | address, | |
| 10 | closed, | |
| 11 | parties: parties.map(([pid, role, name, contact]) => ({ id: pid, deal_id: id, role, name, contact })), | |
| 12 | deadlines: dates.map(([did, owes, label, due, done_at]) => ({ id: did, owes, label, due, done_at })), | |
| 13 | }) as unknown as DealView; | |
| 14 | ||
| 15 | const deals = [ | |
| 16 | deal(1, "B Street", [[1, "lender", "Priya Nair", "[email protected]"]], [[1, "lender", "Financing", "2026-10-20", null], [2, "buyer", "Inspection", "2026-10-11", null]]), | |
| 17 | deal(2, "A Street", [[5, "lender", "Priya N., Coastline", " [email protected] "], [6, "title", "Tess", "[email protected]"]], [ | |
| 18 | [3, "lender", "Appraisal", "2026-10-05", null], | |
| 19 | [4, "lender", "Rate lock", "2026-10-02", "2026-10-02T10:00:00Z"], | |
| 20 | [5, "title", "Title search", "2026-10-30", null], | |
| 21 | ]), | |
| 22 | ]; | |
| 23 | ||
| 24 | test("parties with the same contact, trimmed and case-insensitive, are one person under the newest name", () => { | |
| 25 | expect(personKey({ name: "x", contact: " [email protected] " })).toBe("[email protected]"); | |
| 26 | const all = people(deals, on); | |
| 27 | const priya = all.find((p) => p.contact === "[email protected]")!; | |
| 28 | expect(all.filter((p) => p.name.startsWith("Priya"))).toHaveLength(1); | |
| 29 | expect(priya.name).toBe("Priya N., Coastline"); | |
| 30 | expect(priya.roles).toEqual(["Lender"]); | |
| 31 | }); | |
| 32 | ||
| 33 | test("a person's open dates come from every deal, soonest first, and a done date is left out", () => { | |
| 34 | const priya = people(deals, on)[0]!; | |
| 35 | expect(priya.owes.map((o) => [o.label, o.address, o.urgency])).toEqual([ | |
| 36 | ["Appraisal", "A Street", "overdue"], | |
| 37 | ["Financing", "B Street", "later"], | |
| 38 | ]); | |
| 39 | }); | |
| 40 | ||
| 41 | test("people who owe nothing open come last; a closed deal's dates are not chased", () => { | |
| 42 | const all = people([...deals, deal(3, "C", [[9, "buyer", "Zed", "zed"]], [[9, "buyer", "Offer", "2026-10-01", null]], true)], on); | |
| 43 | expect(all.map((p) => p.name)).toEqual(["Priya N., Coastline", "Tess", "Zed"]); | |
| 44 | expect(all.at(-1)!.owes).toEqual([]); | |
| 45 | }); |
src/people.ts added +74
| @@ -0,0 +1,74 @@ | ||
| 1 | /** | |
| 2 | * The people on the agent's deals and what each owes: every party of every | |
| 3 | * deal, one person per contact, with every open date they owe across deals. | |
| 4 | * Plain data from deals and a day; the page, the API and the MCP tool share it. | |
| 5 | */ | |
| 6 | ||
| 7 | import { urgency, type Urgency } from "./dates.ts"; | |
| 8 | import type { DealView } from "./deals.ts"; | |
| 9 | import { PARTY_LABEL, type PartyRole } from "./deadlines.ts"; | |
| 10 | ||
| 11 | export interface Owed { | |
| 12 | readonly deal_id: number; | |
| 13 | readonly address: string; | |
| 14 | readonly deadline_id: number; | |
| 15 | readonly label: string; | |
| 16 | /** ISO date. */ | |
| 17 | readonly due: string; | |
| 18 | readonly urgency: Urgency; | |
| 19 | } | |
| 20 | ||
| 21 | export interface Person { | |
| 22 | /** The name on the person's most recently added party row. */ | |
| 23 | readonly name: string; | |
| 24 | readonly contact: string; | |
| 25 | /** The roles they hold across deals, as words, in the order first met. */ | |
| 26 | readonly roles: readonly string[]; | |
| 27 | /** Open dates they owe, soonest first, then by address. */ | |
| 28 | readonly owes: readonly Owed[]; | |
| 29 | } | |
| 30 | ||
| 31 | /** Two parties are one person when their contact is the same, ignoring case and outer spaces; with no contact, their name. */ | |
| 32 | export const personKey = (p: { name: string; contact: string }): string => | |
| 33 | (p.contact.trim() === "" ? p.name : p.contact).trim().toLowerCase(); | |
| 34 | ||
| 35 | export function people(deals: readonly DealView[], on: string): Person[] { | |
| 36 | const byKey = new Map<string, { name: string; newest: number; contact: string; roles: Set<PartyRole>; owes: Map<number, Owed> }>(); | |
| 37 | for (const deal of deals) { | |
| 38 | for (const party of deal.parties) { | |
| 39 | const key = personKey(party); | |
| 40 | const one = byKey.get(key) ?? { name: party.name, newest: -1, contact: party.contact.trim(), roles: new Set(), owes: new Map() }; | |
| 41 | byKey.set(key, one); | |
| 42 | if (party.id > one.newest) { | |
| 43 | one.newest = party.id; | |
| 44 | one.name = party.name; | |
| 45 | one.contact = party.contact.trim(); | |
| 46 | } | |
| 47 | one.roles.add(party.role); | |
| 48 | // A closed deal is off the clock: nothing on it is chased. | |
| 49 | if (deal.closed) continue; | |
| 50 | for (const d of deal.deadlines) { | |
| 51 | if (d.owes !== party.role || d.done_at !== null) continue; | |
| 52 | one.owes.set(d.id, { | |
| 53 | deal_id: deal.id, | |
| 54 | address: deal.address, | |
| 55 | deadline_id: d.id, | |
| 56 | label: d.label, | |
| 57 | due: d.due, | |
| 58 | urgency: urgency(d.due, on, false), | |
| 59 | }); | |
| 60 | } | |
| 61 | } | |
| 62 | } | |
| 63 | return [...byKey.values()] | |
| 64 | .map((p) => ({ | |
| 65 | name: p.name, | |
| 66 | contact: p.contact, | |
| 67 | roles: [...p.roles].map((r) => PARTY_LABEL[r]), | |
| 68 | owes: [...p.owes.values()].sort((a, b) => a.due.localeCompare(b.due) || a.address.localeCompare(b.address)), | |
| 69 | })) | |
| 70 | .sort((a, b) => { | |
| 71 | if ((a.owes.length === 0) !== (b.owes.length === 0)) return a.owes.length === 0 ? 1 : -1; | |
| 72 | return (a.owes[0]?.due ?? "").localeCompare(b.owes[0]?.due ?? "") || a.name.localeCompare(b.name); | |
| 73 | }); | |
| 74 | } |
src/routes.ts +54
| @@ -34,6 +34,7 @@ import { | ||
| 34 | 34 | staticFile, |
| 35 | 35 | text, |
| 36 | 36 | } from "./http.ts"; |
| 37 | import type { Verb } from "./can.ts"; | |
| 37 | 38 | import { events } from "./live.ts"; |
| 38 | 39 | import { today } from "./dates.ts"; |
| 39 | 40 | import { |
| @@ -63,6 +64,8 @@ import { FIND_REFUSAL, find, query } from "./find.ts"; | ||
| 63 | 64 | import { clock } from "./pages/clock.ts"; |
| 64 | 65 | import { dealPage, newDealPage } from "./pages/deal.ts"; |
| 65 | 66 | import { refusedPage } from "./pages/refused.ts"; |
| 67 | import { people } from "./people.ts"; | |
| 68 | import { peoplePage } from "./pages/people.ts"; | |
| 66 | 69 | import { timelinePage } from "./pages/timeline.ts"; |
| 67 | 70 | import { welcomePage } from "./pages/welcome.ts"; |
| 68 | 71 | import { dueOn } from "./reminders.ts"; |
| @@ -90,6 +93,8 @@ export interface Api { | ||
| 90 | 93 | readonly status?: number; |
| 91 | 94 | /** The query parameters it reads. */ |
| 92 | 95 | readonly query?: Readonly<Record<string, Schema>>; |
| 96 | /** The cell of the table a route outside its resource's `api` path reads through, for the description. */ | |
| 97 | readonly cell?: { readonly resource: string; readonly verb: Verb }; | |
| 93 | 98 | } |
| 94 | 99 | |
| 95 | 100 | export interface Route { |
| @@ -122,6 +127,28 @@ const PARTY: Schema = { | ||
| 122 | 127 | type: "object", |
| 123 | 128 | properties: { id: { type: "integer" }, role: ROLE, name: { type: "string" }, contact: { type: "string" } }, |
| 124 | 129 | }; |
| 130 | export const PERSON: Schema = { | |
| 131 | type: "object", | |
| 132 | properties: { | |
| 133 | name: { type: "string" }, | |
| 134 | contact: { type: "string" }, | |
| 135 | roles: { type: "array", items: { type: "string" } }, | |
| 136 | owes: { | |
| 137 | type: "array", | |
| 138 | items: { | |
| 139 | type: "object", | |
| 140 | properties: { | |
| 141 | deal_id: { type: "integer" }, | |
| 142 | address: { type: "string" }, | |
| 143 | deadline_id: { type: "integer" }, | |
| 144 | label: { type: "string" }, | |
| 145 | due: DATE, | |
| 146 | urgency: { enum: ["overdue", "soon", "later"] }, | |
| 147 | }, | |
| 148 | }, | |
| 149 | }, | |
| 150 | }, | |
| 151 | }; | |
| 125 | 152 | export const DEAL: Schema = { |
| 126 | 153 | type: "object", |
| 127 | 154 | properties: { |
| @@ -345,6 +372,19 @@ export const routes: readonly Route[] = [ | ||
| 345 | 372 | return html(clock({ who: c.who, deals: deals.value, on: today(), notice, q }), 200, clear); |
| 346 | 373 | }, |
| 347 | 374 | }, |
| 375 | { | |
| 376 | method: "GET", | |
| 377 | path: "/people", | |
| 378 | handle: (c) => { | |
| 379 | const deals = listDeals(c.db, c.who); | |
| 380 | if (!deals.ok) | |
| 381 | return html( | |
| 382 | refusedPage({ who: c.who, path: "/people", heading: "People", error: deals.error, message: deals.message }), | |
| 383 | STATUS[deals.error], | |
| 384 | ); | |
| 385 | return html(peoplePage({ who: c.who, people: people(deals.value, today()), on: today() })); | |
| 386 | }, | |
| 387 | }, | |
| 348 | 388 | { |
| 349 | 389 | method: "GET", |
| 350 | 390 | path: "/deals/new", |
| @@ -608,6 +648,20 @@ export const routes: readonly Route[] = [ | ||
| 608 | 648 | query: { q: { type: "string", maxLength: 100 } }, |
| 609 | 649 | }, |
| 610 | 650 | }, |
| 651 | { | |
| 652 | method: "GET", | |
| 653 | path: "/api/people", | |
| 654 | handle: (c) => { | |
| 655 | const deals = listDeals(c.db, c.who); | |
| 656 | return answer(deals.ok ? { ok: true, value: people(deals.value, today()) } : deals); | |
| 657 | }, | |
| 658 | api: { | |
| 659 | summary: | |
| 660 | "Each person on your deals once (parties with the same contact are one), with their roles and every open date they owe across deals, soonest first; people who owe nothing open come last.", | |
| 661 | answer: list(PERSON), | |
| 662 | cell: { resource: "deal", verb: "list" }, | |
| 663 | }, | |
| 664 | }, | |
| 611 | 665 | { |
| 612 | 666 | method: "POST", |
| 613 | 667 | path: "/api/deals", |
src/server.test.ts +19
| @@ -168,6 +168,7 @@ test("the MCP server lists the tools and calls them as the caller", async () => | ||
| 168 | 168 | "client_timeline", |
| 169 | 169 | "reminders_today", |
| 170 | 170 | "this_week", |
| 171 | "list_people", | |
| 171 | 172 | "mark_done", |
| 172 | 173 | "move_date", |
| 173 | 174 | "send_reminder", |
| @@ -1056,3 +1057,21 @@ test("an agent finds a deal by name over MCP and GET /api/deals?q=, with one ref | ||
| 1056 | 1057 | expect((await call({ query: 5 })).isError).toBe(true); |
| 1057 | 1058 | expect((await api("/api/deals?q=a%01", {}, alice)).status).toBe(400); |
| 1058 | 1059 | }); |
| 1060 | ||
| 1061 | test("People lists each person once with the dates they owe, the page and the API agree, and a stranger is refused", async () => { | |
| 1062 | const pat = as("u-people", "pat"); | |
| 1063 | expect((await api("/people")).status).toBe(401); | |
| 1064 | const page = await (await api("/people", {}, pat)).text(); | |
| 1065 | const people = (await (await api("/api/people", {}, pat)).json()) as any[]; | |
| 1066 | const priya = people.filter((p) => p.contact === "[email protected]"); | |
| 1067 | expect(priya).toHaveLength(1); | |
| 1068 | const deals = new Set(priya[0].owes.map((o: any) => o.address)); | |
| 1069 | expect(deals.size).toBeGreaterThan(1); | |
| 1070 | expect(priya[0].owes.every((o: any, i: number, all: any[]) => i === 0 || all[i - 1].due <= o.due)).toBe(true); | |
| 1071 | expect(page).not.toContain("<script"); | |
| 1072 | for (const p of people) expect(page).toContain(`<h2>${p.name.replace(/&/g, "&")}</h2>`); | |
| 1073 | for (const o of priya[0].owes) expect(page).toContain(`href="/deals/${o.deal_id}"`); | |
| 1074 | expect(page).toContain('href="/people"'); | |
| 1075 | const list = JSON.parse((await rpc({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "list_people", arguments: {} } }, pat)).result.content[0].text); | |
| 1076 | expect(list).toEqual(people); | |
| 1077 | }); |
src/terminal.test.ts +21
| @@ -457,3 +457,24 @@ test("a signed-out terminal is not asked for an address", () => { | ||
| 457 | 457 | t.press("A"); |
| 458 | 458 | expect(deal().address).toBe("12 Elm St"); |
| 459 | 459 | }); |
| 460 | ||
| 461 | test("P lists each person once with the dates they owe across deals; a guest is refused", () => { | |
| 462 | const own = openDb(mkdtempSync(join(tmpdir(), "app-terminal-people-"))); | |
| 463 | const open = (address: string) => { | |
| 464 | const made = createDeal(own, alice, { address, buyer: "B", seller: "S", contractDate: today(), closingDate: addDays(today(), 30) }); | |
| 465 | if (!made.ok) throw new Error(made.message); | |
| 466 | addParty(own, alice, { dealId: made.value.id, role: "lender", name: "Lena Lender", contact: "[email protected]" }); | |
| 467 | }; | |
| 468 | open("1 Shared Lane"); | |
| 469 | open("2 Shared Lane"); | |
| 470 | const t = terminal(own, alice, context); | |
| 471 | t.press("P"); | |
| 472 | const screen = lines(t).join("\n"); | |
| 473 | expect(screen.match(/Lena Lender/g)).toHaveLength(1); | |
| 474 | expect(screen).toContain("1 Shared Lane"); | |
| 475 | expect(screen).toContain("2 Shared Lane"); | |
| 476 | expect(screen).toContain("Nothing open"); | |
| 477 | const guest = terminal(own, { role: "anon" }, context); | |
| 478 | guest.press("P"); | |
| 479 | expect(lines(guest).join("\n")).not.toContain("Lena Lender"); | |
| 480 | }); |
src/terminal.ts +24 −4
| @@ -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 | * people each person on the deals with every open date they owe (P) | |
| 9 | 10 | * timeline a deal's dates as a client would get them (t on a deal) |
| 10 | 11 | * deal one deal's dates and parties; a adds a date, p a party, A corrects the address, D removes it |
| 11 | 12 | * |
| @@ -52,6 +53,7 @@ import { PARTY_LABEL, PARTY_ROLES, type PartyRole } from "./deadlines.ts"; | ||
| 52 | 53 | import { drafts, MOMENT_LABEL, pending, unsent, type Agent, type Draft } from "./reminders.ts"; |
| 53 | 54 | import type { Result } from "./result.ts"; |
| 54 | 55 | import type { Who } from "./who.ts"; |
| 56 | import { people } from "./people.ts"; | |
| 55 | 57 | import { owner, thisWeek } from "./week.ts"; |
| 56 | 58 | |
| 57 | 59 | const esc = "\x1b["; |
| @@ -60,7 +62,7 @@ const bold = (s: string): string => `${esc}1m${s}${esc}0m`; | ||
| 60 | 62 | const COLOUR: Readonly<Record<Urgency, string>> = { overdue: "31", soon: "33", later: "36", done: "2" }; |
| 61 | 63 | const tint = (u: Urgency, s: string): string => `${esc}${COLOUR[u]}m${s}${esc}0m`; |
| 62 | 64 | |
| 63 | type View = "dates" | "week" | "reminders" | "deal" | "messages" | "timeline"; | |
| 65 | type View = "dates" | "week" | "people" | "reminders" | "deal" | "messages" | "timeline"; | |
| 64 | 66 | interface Row { |
| 65 | 67 | readonly deal: DealView; |
| 66 | 68 | readonly date: DeadlineView; |
| @@ -367,6 +369,9 @@ export function terminal( | ||
| 367 | 369 | } else if (key === "w") { |
| 368 | 370 | view = "week"; |
| 369 | 371 | cursor = 0; |
| 372 | } else if (key === "P") { | |
| 373 | view = "people"; | |
| 374 | cursor = 0; | |
| 370 | 375 | } else if (key === "r") { |
| 371 | 376 | view = "reminders"; |
| 372 | 377 | cursor = 0; |
| @@ -445,7 +450,7 @@ export function terminal( | ||
| 445 | 450 | const lines = [ |
| 446 | 451 | `${bold(context.title)} ${context.agent.name}, ${context.agent.brokerage} ${dim(`${context.agent.phone} · ${context.agent.email}`)} ${dim(context.where)} ${dim(me.role === "anon" ? "guest" : `${me.name}${me.role === "admin" ? " (admin)" : ""}`)}`, |
| 447 | 452 | context.ssh === undefined ? dim("The terminal is off.") : dim(`connect: ${context.ssh}`), |
| 448 | `${spoken(day)} · ${all.length} deals · ${view === "dates" ? bold("[d] dates") : "[d] dates"} · ${view === "week" ? bold("[w] this week") : "[w] this week"} · ${view === "reminders" ? bold("[r] reminders today") : "[r] reminders today"}`, | |
| 453 | `${spoken(day)} · ${all.length} deals · ${view === "dates" ? bold("[d] dates") : "[d] dates"} · ${view === "week" ? bold("[w] this week") : "[w] this week"} · ${view === "reminders" ? bold("[r] reminders today") : "[r] reminders today"} · ${view === "people" ? bold("[P] people") : "[P] people"}`, | |
| 449 | 454 | "", |
| 450 | 455 | ]; |
| 451 | 456 | if (found !== "" && (view === "dates" || view === "week" || view === "reminders")) |
| @@ -476,6 +481,19 @@ export function terminal( | ||
| 476 | 481 | heading = h; |
| 477 | 482 | lines.push(dateLine(row, i, true)); |
| 478 | 483 | }); |
| 484 | } else if (view === "people") { | |
| 485 | const listed = listDeals(db, me); | |
| 486 | if (!listed.ok) lines.push(listed.message); | |
| 487 | else { | |
| 488 | const all = people(listed.value, day); | |
| 489 | if (all.length === 0) lines.push(dim("No one yet: add a deal and its parties.")); | |
| 490 | for (const p of all) { | |
| 491 | lines.push(`${bold(p.name)} ${dim(`${p.roles.join(", ")}${p.contact === "" ? "" : ` · ${p.contact}`}`)}`); | |
| 492 | if (p.owes.length === 0) lines.push(dim(" Nothing open")); | |
| 493 | for (const o of p.owes) | |
| 494 | lines.push(` ${tint(o.urgency, `${spoken(o.due).padEnd(12)} ${relative(o.due, day).padEnd(12)}`)} ${o.label} — ${o.address}`); | |
| 495 | } | |
| 496 | } | |
| 479 | 497 | } else if (view === "messages") { |
| 480 | 498 | const deal = openDeal(); |
| 481 | 499 | if (deal === undefined) lines.push(dim("That deal is gone.")); |
| @@ -529,7 +547,9 @@ export function terminal( | ||
| 529 | 547 | else { |
| 530 | 548 | if (said !== "") lines.push(...said.split("\n")); |
| 531 | 549 | const keys = |
| 532 | view === "reminders" | |
| 550 | view === "people" | |
| 551 | ? "P people · d dates · w this week · r reminders · q quit" | |
| 552 | : view === "reminders" | |
| 533 | 553 | ? "j/k move · enter read · e edit · s send · n don't send · u undo · / find · d dates · q quit" |
| 534 | 554 | : view === "messages" |
| 535 | 555 | ? "j/k move · enter read · b back to the deal · d dates · q quit" |
| @@ -537,7 +557,7 @@ export function terminal( | ||
| 537 | 557 | ? "b back to the deal · d dates · q quit" |
| 538 | 558 | : view === "deal" |
| 539 | 559 | ? "j/k move · t client timeline · s messages · x done · u reopen · m move · a add date · p add party · e edit party · A edit address · X remove date/party · D remove deal · b back · q quit" |
| 540 | : `j/k move · x done · u reopen · m move · o open deal · n new deal · c check dates · / find · R restore samples · h ${showDone ? "hide" : "show"} done · w this week · r reminders · q quit`; | |
| 560 | : `j/k move · x done · u reopen · m move · 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 · q quit`; | |
| 541 | 561 | lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys)); |
| 542 | 562 | } |
| 543 | 563 | return lines; |
static/app.css +9
| @@ -777,6 +777,15 @@ textarea.input { | ||
| 777 | 777 | border-bottom: 1px solid var(); |
| 778 | 778 | cursor: pointer; |
| 779 | 779 | } |
| 780 | a.week-row { | |
| 781 | text-decoration: none; | |
| 782 | } | |
| 783 | .person h2 { | |
| 784 | margin: 0; | |
| 785 | } | |
| 786 | .person p { | |
| 787 | margin: var() 0 0; | |
| 788 | } | |
| 780 | 789 | .week-what { |
| 781 | 790 | display: grid; |
| 782 | 791 | min-width: 0; |
new above
offline