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

People can be narrowed by typing a name, phone or address, like the clock's Find #249

Merged opened this

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

Merged

mason/deal-clock:mason/247-people-can-be-narrowed-by-typing-a-name → main 2 commits fork 3 threads · 3 unresolved

  • Merged. mason/247-people-can-be-narrowed-by-typing-a-name was merged into main as d5aef3a.

Review

Sign in to review this change.
8 files changed +103 −13
README.md +5 −2
@@ -69,8 +69,11 @@ looks like today.
6969 first. Try Priya Nair, the lender on both 1418 Alder Lane and 9 Orchard Row.
7070 Each person also shows when you last sent them a reminder or notice, and
7171 about what ("Last heard Nov 6 · Financing, 12 Oak Lane"), or "Nothing sent
72 yet"; declined and held drafts don't count. Tap a number to call or text,
73 an address to write. In the terminal press P; over MCP ask for `list_people`.
72 yet"; declined and held drafts don't count. Type a name, phone, email or
73 address into **Find a person** to narrow the list (try "priya"); **Clear**
outdated

Rewrap these long lines and mention / in the terminal once the terminal People view supports it.

74 brings everyone back. Tap a number to call or text, an address to write. In
75 the terminal press P, then / to find a person (enter alone clears it); over
76 MCP ask for `list_people`.
7477 10. **Set up your Profile.** Open **Profile** in the header and type your name,
7578 brokerage, phone and email. They appear in the header, on the client
7679 timeline and at the foot of every new reminder. (Only an admin can save
src/pages/people.ts +8 −2
@@ -29,10 +29,16 @@ const person = (p: Person, on: string): string => `<section class="card person">
2929 ${p.owes.length === 0 ? `<p class="muted">Nothing open</p>` : `<ul class="week-list">${p.owes.map((o) => owedRow(o, on)).join("")}</ul>`}
3030 </section>`;
3131
32 export function peoplePage(input: { who: Who; agent?: Agent | undefined; waiting?: number | undefined; people: readonly Person[]; on: string }): string {
32 export function peoplePage(input: { who: Who; agent?: Agent | undefined; waiting?: number | undefined; people: readonly Person[]; on: string; q?: string }): string {
outdated

total is never used; remove it here and in routes.ts.

3333 const { who, people, on } = input;
34 const q = input.q ?? "";
3435 const body = `<h1>People</h1>
3536 <p class="summary">Everyone on your deals, with every open date they owe, soonest first.</p>
36 ${people.length === 0 ? `<p class="muted">No one yet: add a deal and its parties.</p>` : people.map((p) => person(p, on)).join("")}`;
37 <form class="find" method="get" action="/people" role="search">
38 <label for="find-q">Find a person</label>
39 <input id="find-q" class="input" type="search" name="q" value="${escape(q)}" maxlength="100" placeholder="Name, phone, email or address" autocomplete="off">
40 <button class="btn" type="submit">Find</button>
41 </form>
42 ${people.length === 0 ? (q !== "" ? `<p class="muted">No one matches “${escape(q)}”. <a href="/people">Clear</a></p>` : `<p class="muted">No one yet: add a deal and its parties.</p>`) : people.map((p) => person(p, on)).join("")}`;
3743 return layout({ body, who, agent: input.agent, waiting: input.waiting, path: "/people", heading: "People", live: false });
3844 }
src/people.test.ts +21 −1
@@ -1,6 +1,6 @@
11 import { expect, test } from "bun:test";
22 import type { DealView } from "./deals.ts";
3 import { nudgeLine, people, personKey } from "./people.ts";
3 import { narrowPeople, nudgeLine, people, personKey } from "./people.ts";
44
55 const on = "2026-10-10";
66 const deal = (id: number, address: string, parties: [number, string, string, string][], dates: [number, string, string, string, string | null][], closed = false): DealView =>
@@ -91,3 +91,23 @@ test("flagged people come first, soonest date first; the rest keep their order",
9191 const calm = deal(9, "Z", [[20, "buyer", "Aaron", "aaron"]], [[20, "buyer", "Offer", "2026-10-30", null]]);
9292 expect(people([calm, mk(a, 2, "Late", "l@x"), mk(b, 3, "Early", "e@x")], "2026-10-10").map((p) => p.name)).toEqual(["Early", "Late", "Aaron"]);
9393 });
94
95 test("narrowPeople keeps people whose name, email, phone or owed address contains the query, flags untouched", () => {
96 const all = people(deals, on);
97 expect(narrowPeople(all, "")).toHaveLength(all.length);
98 expect(narrowPeople(all, " TESS ").map((p) => p.name)).toEqual(["Tess"]);
99 expect(narrowPeople(all, "bank.example").map((p) => p.name)).toEqual(["Priya N., Coastline"]);
100 expect(narrowPeople(all, "b street").map((p) => p.name)).toEqual(["Priya N., Coastline"]);
101 expect(narrowPeople(all, "zzz")).toEqual([]);
102 expect(narrowPeople(all, "tess")[0]!.nudge).toBe(all.find((p) => p.name === "Tess")!.nudge);
103 });
104
105 test("the People page shows the box, escapes the query and says No one matches with a clear link", async () => {
106 const { peoplePage } = await import("./pages/people.ts");
107 const who = { role: "anon" } as const;
108 const html = peoplePage({ who, people: [], on, q: "<b>x</b>" });
109 expect(html).toContain('action="/people"');
110 expect(html).toContain("No one matches");
111 expect(html).toContain('href="/people"');
112 expect(html).not.toContain("<b>x</b>");
113 });
src/people.ts +9
@@ -215,3 +215,12 @@ export function matchKnown(known: readonly Known[], text: string): Known[] {
215215 const t = text.trim().toLowerCase();
216216 return t === "" ? [...known] : known.filter((k) => [k.name, ...k.roles, k.email, k.phone].some((v) => v.toLowerCase().includes(t)));
217217 }
218
219 /** The people whose name, email, phone or an owed address contains `q`, case-insensitively; an empty `q` keeps them all. Flags are left as computed. */
220 export function narrowPeople(all: readonly Person[], q: string): Person[] {
221 const needle = q.trim().toLowerCase();
222 if (needle === "") return [...all];
223 return all.filter((p) =>
224 [p.name, p.email, p.phone, p.contact, ...p.owes.map((o) => o.address)].join("\n").toLowerCase().includes(needle),
225 );
226 }
src/peopleroute.test.ts added +33
@@ -0,0 +1,33 @@
1 /** GET /people?q= narrows the list to matches; a bad q is refused with 400. */
2 import { afterAll, beforeEach, expect, test } from "bun:test";
3 import { mkdtempSync } from "node:fs";
4 import { tmpdir } from "node:os";
5 import { join } from "node:path";
6 import { forgetRationing } from "./security.ts";
7 import { serve } from "./server.ts";
8 import { sign } from "./who.ts";
9
10 const KEY = "a-key-only-the-forge-holds";
11 const server = serve({ port: 0, dataDir: mkdtempSync(join(tmpdir(), "app-peopleroute-")), identityKey: KEY });
12 const base = `http://${server.hostname}:${server.port}`;
13 afterAll(() => server.stop(true));
14 beforeEach(forgetRationing);
15
16 const identity = `u1|alice|user|${Date.now() + 600_000}`;
17 const alice = { "x-forge-identity": identity, "x-forge-signature": sign(identity, KEY) };
18 const get = (q: string) => fetch(`${base}/people?q=${encodeURIComponent(q)}`, { headers: alice });
19 const names = (page: string) => [...page.matchAll(/<h2[^>]*>([^<]*)<\/h2>/g)].map((m) => m[1]!);
20
21 test("/people?q= keeps only the people that match", async () => {
22 const everyone = names(await (await get("")).text());
23 const page = await (await get("priya")).text();
24 const found = names(page);
25 expect(found.length).toBeGreaterThan(0);
26 expect(found.length).toBeLessThan(everyone.length);
27 expect(found.every((n) => /priya/i.test(n))).toBe(true);
28 });
29
30 test("an over-long or control-character q is refused with 400", async () => {
31 expect((await get("a".repeat(101))).status).toBe(400);
32 expect((await get("a\u0001b")).status).toBe(400);
33 });
src/routes.ts +6 −2
@@ -100,7 +100,7 @@ import { dealSheets } from "./pages/sheet.ts";
100100 import { dealPage, newDealPage } from "./pages/deal.ts";
101101 import { missingPage } from "./pages/missing.ts";
102102 import { refusedPage } from "./pages/refused.ts";
103 import { knownPeople, people } from "./people.ts";
103 import { knownPeople, narrowPeople, people } from "./people.ts";
104104 import { reviewHref, reviewPage, type ReviewError, type ReviewField } from "./pages/review.ts";
105105 import { peoplePage } from "./pages/people.ts";
106106 import { activityPage } from "./pages/activity.ts";
@@ -808,7 +808,11 @@ export const routes: readonly Route[] = [
808808 refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: "/people", heading: "People", error: deals.error, message: deals.message }),
809809 STATUS[deals.error],
810810 );
811 return html(peoplePage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), people: people(deals.value, dayOf(agentFor(c))), on: dayOf(agentFor(c)) }));
811 const q = query(c.url.searchParams.get("q"));
812 if (q === undefined)
813 return html(refusedPage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), path: "/people", heading: "People", error: "invalid", message: FIND_REFUSAL }), 400);
814 const everyone = people(deals.value, dayOf(agentFor(c)));
815 return html(peoplePage({ who: c.who, waiting: waitingFor(c), agent: agentFor(c), people: narrowPeople(everyone, q), on: dayOf(agentFor(c)), q }));
outdated

Passes total that nothing reads. Drop it. Also needs a route test for q and the 400 case.

812816 },
813817 },
814818 {
src/terminal.test.ts +14
@@ -482,6 +482,20 @@ test("/ finds a deal and narrows dates, week and reminders to it; / then enter c
482482 expect(all).not.toContain("Finding");
483483 });
484484
485 test("/ in People narrows the list by name; / then enter clears it", () => {
486 const t = terminal(db, alice, context);
487 t.press("P");
488 const all = lines(t).join("\n");
489 press(t, "/", "zzzz-nobody\r");
490 const none = lines(t).join("\n");
491 expect(none).toContain("Finding “zzzz-nobody”");
492 expect(none).toContain("No one matches “zzzz-nobody”.");
493 press(t, "/", "\r");
494 const back = lines(t).join("\n");
495 expect(back).not.toContain("Finding");
496 expect(back).toContain(all.split("\n").find((l) => l.includes("Buyer")) ?? "");
497 });
498
485499 test("A corrects the address of the open deal; a too-short one is refused and nothing changes", () => {
486500 const own = createDeal(db, alice, { openAnyway: true, address: "3 Oak St", buyer: "Bea Buyer", seller: "Sid Seller", contractDate: today(DEFAULT_ZONE), closingDate: addDays(today(DEFAULT_ZONE), 30) });
487501 if (!own.ok) throw new Error(own.message);
src/terminal.ts +7 −6
@@ -83,7 +83,7 @@ import { drafts, heldFrom, inClockOrder, momentLabel, pending, remindsLine, sent
8383 import type { AuditRow } from "./audit.ts";
8484 import type { Result } from "./result.ts";
8585 import type { Who } from "./who.ts";
86 import { nudgeLine, people } from "./people.ts";
86 import { narrowPeople, nudgeLine, people } from "./people.ts";
8787 import { reachedAt } from "./outbox.ts";
8888 import { addresses, refusal, when, wording } from "./activity.ts";
8989 import { listAudit } from "./actions.ts";
@@ -633,9 +633,9 @@ export function terminal(
633633 showHeld = false;
634634 cursor = 0;
635635 reading = undefined;
636 } else if (key === "/" && (view === "dates" || view === "week" || view === "reminders")) {
636 } else if (key === "/" && (view === "dates" || view === "week" || view === "reminders" || view === "people")) {
637637 prompt = {
638 steps: [`Find a deal (address, client or party; enter alone clears${found === "" ? "" : `; now “${found}”`})`],
638 steps: [`${view === "people" ? "Find a person (name, phone, email or address" : "Find a deal (address, client or party"}; enter alone clears${found === "" ? "" : `; now “${found}”`})`],
639639 answers: [],
640640 text: "",
641641 max: FIND_MAX,
@@ -644,6 +644,7 @@ export function terminal(
644644 if (q === undefined) return `Find takes up to ${FIND_MAX} characters, with no control characters.`;
645645 found = q;
646646 cursor = 0;
647 if (view === "people") return q === "" ? "Showing everyone." : `Showing people that match “${q}”. / then enter clears it.`;
647648 return q === "" ? "Showing every deal." : deals().length === 0 ? `No deal matches “${q}”. / then enter clears it.` : `Showing deals that match “${q}”.`;
648649 },
649650 };
@@ -776,7 +777,7 @@ export function terminal(
776777 `${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"}`,
777778 "",
778779 ];
779 if (found !== "" && (view === "dates" || view === "week" || view === "reminders"))
780 if (found !== "" && (view === "dates" || view === "week" || view === "reminders" || view === "people"))
780781 lines.splice(3, 0, dim(`Finding “${found}” — / changes it, / then enter clears it`));
781782 if (view === "dates") {
782783 const rows = dateRows();
@@ -817,8 +818,8 @@ export function terminal(
817818 const listed = listDeals(db, me);
818819 if (!listed.ok) lines.push(listed.message);
819820 else {
820 const all = people(listed.value, day);
821 if (all.length === 0) lines.push(dim("No one yet: add a deal and its parties."));
821 const all = narrowPeople(people(listed.value, day), found);
822 if (all.length === 0) lines.push(dim(found === "" ? "No one yet: add a deal and its parties." : `No one matches “${found}”.`));
822823 for (const p of all) {
823824 lines.push(`${bold(p.name)} ${dim(`${p.roles.join(", ")}${reachedAt(p) === "" ? "" : ` · ${reachedAt(p)}`}`)}`);
824825 if (p.nudge !== null) lines.push(` ${tint("soon", nudgeLine(p.nudge, day))}`);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs