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

Under the clock, a This week list gives every open date in the next seven days, day by day, readable on a phone without scrolling sideways #27

Merged opened this

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

Merged

mason/deal-clock:mason/13-under-the-clock-a-this-week-list-gives-e → main 4 commits fork

  • Merged. mason/13-under-the-clock-a-this-week-list-gives-e was merged into main as cfd3c1e.

Review

Sign in to review this change.
11 files changed +260 −12
README.md +6 −1
@@ -15,7 +15,12 @@ left to right, and today is the dark line down the middle. Every date in a
1515 contract is a marker on its lane: red is overdue, amber is due within three
1616 days, teal is coming up, grey is done. The samples stay current: each time
1717 the app starts, the ones nobody has touched move forward together by the days
18 since they were last set, so the screen always looks like today.
18 since they were last set, so the screen always looks like today. Under the
19 clock, **This week** lists every open date that is overdue or due in the next
20 seven days, day by day (Overdue, Today, then each day), with the deal's
21 address, who owes it and how urgent it is; tap a row to open its sheet. It
22 reads well on a phone, with no sideways scrolling. In the terminal, press w
23 for the same list; over MCP, an agent asks for the `this_week` tool.
1924
2025 1. **Look at the clock.** You see four lanes: 77 Harbor View Dr, Unit 4B
2126 (the inspection date has passed, so its marker is red), 1418 Alder Lane
docs/TECHNICAL.md +2 −2
@@ -40,7 +40,7 @@ reason on the reminders list, and `u` to undo. Each is an update of the deal.
4040 marked sent, as JSON — call it each morning as a signed-in account (a
4141 stranger gets 401; it sends nothing and changes nothing). `GET /deals/:id/ics` is a deal's calendar file. The JSON API is
4242 `/api/deals`, described at `/openapi.json`; the same operations are MCP
43 tools at `POST /mcp` (`list_deals`, `get_deal`, `reminders_today`,
43 tools at `POST /mcp` (`list_deals`, `get_deal`, `reminders_today`, `this_week`,
4444 `open_deal`, `add_date`, `add_party`, `edit_party`, `remove_party`,
4545 `remove_date` — custom dates only — `remove_deal` — its author or an admin —
4646 `mark_done` — with `done: false` to
@@ -57,7 +57,7 @@ its deal — where `a` adds a date,
5757 `p` adds a party, `e` edits the party under the cursor (the cursor walks the
5858 dates, then the parties), `X` removes the date or party under it after you
5959 type `yes`, and `D` removes the deal likewise — and `h`
60 shows done dates. `r` lists today's reminders: enter reads a draft, `e`
60 shows done dates. `w` lists the open dates overdue or due in the next seven days, by day (`src/week.ts`, as the This week card). `r` lists today's reminders: enter reads a draft, `e`
6161 types new words for it (a subject, then a message, where `\n` is a line
6262 break and an empty answer keeps the draft's), and `s` sends what you read,
6363 under the same limits as the page. `j`/`k` move, `b` goes back, `q` quits. What you change there
src/mcp.ts +20
@@ -29,6 +29,7 @@ import {
2929 import { agent, title } from "./env.ts";
3030 import { dueOn } from "./reminders.ts";
3131 import { fields } from "./http.ts";
32 import { owner, thisWeek } from "./week.ts";
3233 import type { Who } from "./who.ts";
3334
3435 interface Tool {
@@ -64,6 +65,25 @@ export const tools: readonly Tool[] = [
6465 return deals.ok ? { ok: true, value: dueOn(deals.value, today(), agent) } : deals;
6566 },
6667 },
68 {
69 name: "this_week",
70 description: "Every open date that is overdue or due in the next seven days, oldest first, then by address, with the deal's address and who owes it.",
71 inputSchema: { type: "object", properties: {} },
72 run: (db, who) => {
73 const deals = listDeals(db, who);
74 return deals.ok
75 ? {
76 ok: true,
77 value: thisWeek(deals.value, today()).map(({ deal, deadline }) => ({
78 deal_id: deal.id,
79 address: deal.address,
80 owner: owner(deal, deadline),
81 deadline,
82 })),
83 }
84 : deals;
85 },
86 },
6787 {
6888 name: "mark_done",
6989 description: "Mark a date done (or reopen it with done: false).",
src/pages/clock.ts +36 −1
@@ -12,8 +12,9 @@ import { agent } from "../env.ts";
1212 import { escape } from "../http.ts";
1313 import { drafts, unsent } from "../reminders.ts";
1414 import type { Who } from "../who.ts";
15 import { thisWeek } from "../week.ts";
1516 import { layout } from "./layout.ts";
16 import { draftItem, sheet, sheetId, URGENCY_LABEL } from "./sheet.ts";
17 import { badge, draftItem, owedBy, sheet, sheetId, URGENCY_LABEL } from "./sheet.ts";
1718 import { canChange } from "../deals.ts";
1819
1920 /** The days the clock shows: a week behind today (further, if something open is older), to a few days past the last closing. */
@@ -76,6 +77,39 @@ function axis(start: string, days: number, on: string): string {
7677 return out.join("");
7778 }
7879
80 /** The day heading a date sits under: overdue ones share one. */
81 const dayHeading = (due: string, on: string): string =>
82 due < on ? "Overdue" : due === on ? "Today" : spoken(due);
83
84 /** Open dates due within the week, under day headings; each row opens its sheet. */
85 function weekCard(deals: readonly DealView[], on: string): string {
86 const items = thisWeek(deals, on);
87 const groups: { heading: string; items: typeof items }[] = [];
88 for (const item of items) {
89 const heading = dayHeading(item.deadline.due, on);
90 const group = groups.at(-1);
91 if (group?.heading === heading) group.items.push(item);
92 else groups.push({ heading, items: [item] });
93 }
94 const body =
95 groups.length === 0
96 ? `<p class="muted">Nothing due in the next seven days.</p>`
97 : groups
98 .map(
99 (g) => `<h3 class="week-day">${escape(g.heading)}</h3>
100 <ul class="week-list">${g.items
101 .map(({ deal, deadline: d }) => {
102 return `<li><button class="week-row" popovertarget="${sheetId(d)}"><span class="week-what"><b>${escape(d.label)}</b><small class="muted">${escape(deal.address)} · ${owedBy(deal, d)}</small></span>${badge(d, on)}</button></li>`;
103 })
104 .join("")}</ul>`,
105 )
106 .join("");
107 return `<section id="week" class="card" data-live="deal.changed">
108 <h2>This week</h2>
109 ${body}
110 </section>`;
111 }
112
79113 export function clock(input: {
80114 who: Who;
81115 deals: readonly DealView[];
@@ -119,6 +153,7 @@ export function clock(input: {
119153 <li><span class="dot" data-u="done"></span>Done</li>
120154 </ul>
121155 </section>
156 ${deals.length === 0 ? "" : weekCard(deals, on)}
122157 <section id="today" class="card" data-live="deal.changed">
123158 <h2>Reminders for today <span class="muted">· ${toSend === 0 ? "all sent" : `${toSend} to send`}</span></h2>
124159 ${
src/pages/sheet.ts +4 −4
@@ -12,6 +12,7 @@ import { agent } from "../env.ts";
1212 import { escape } from "../http.ts";
1313 import { draftsFor, MOMENT_LABEL, MOMENTS, type Draft } from "../reminders.ts";
1414 import type { Who } from "../who.ts";
15 import { owner } from "../week.ts";
1516
1617 export const sheetId = (d: DeadlineView): string => `sheet-${d.id}`;
1718
@@ -35,11 +36,10 @@ export const badge = (d: DeadlineView, on: string): string => {
3536
3637 /** Who owes it, by name when the deal has that party. */
3738 export function owedBy(deal: DealView, d: DeadlineView): string {
38 const party = deal.parties.find((p) => p.role === d.owes);
39 const role = PARTY_LABEL[d.owes];
40 return party === undefined
39 const { name, role } = owner(deal, d);
40 return name === undefined
4141 ? `<b>${escape(role)}</b> <span class="muted">(none on file yet)</span>`
42 : `<b>${escape(party.name)}</b> <span class="muted">· ${escape(role)}</span>`;
42 : `<b>${escape(name)}</b> <span class="muted">· ${escape(role)}</span>`;
4343 }
4444
4545 const hidden = (fields: Record<string, string | number>): string =>
src/server.test.ts +34
@@ -156,6 +156,7 @@ test("the MCP server lists the tools and calls them as the caller", async () =>
156156 "list_deals",
157157 "get_deal",
158158 "reminders_today",
159 "this_week",
159160 "mark_done",
160161 "move_date",
161162 "send_reminder",
@@ -790,3 +791,36 @@ test("Check the dates refuses a guest and writes nothing; a refusal with no fiel
790791 expect(page).toContain("&lt;u&gt;x");
791792 expect(page).not.toContain("-why");
792793 });
794
795 test("This week lists the sample's overdue inspection and this week's closing, and nothing done", async () => {
796 const page = await (await api("/", {}, alice)).text();
797 const week = page.slice(page.indexOf('id="week"'), page.indexOf('id="today"'));
798 expect(week).toContain("This week");
799 expect(week).toContain("Overdue");
800 expect(week).toContain("Inspection period ends");
801 expect(week).toContain("77 Harbor View Dr");
802 expect(week).toContain("Closing");
803 expect(week).toContain("1418 Alder Lane");
804 expect(week).toContain('data-live="deal.changed"');
805 expect(week).toContain("popovertarget=");
806 });
807
808 test("This week over MCP lists the same dates, for a signed-in account only; a date marked done drops off the card", async () => {
809 // Its own account: the write allowance is shared by every test file in one run, and u1 is spent.
810 const week = as("u-week", "wanda");
811 const call = (name: string, args: unknown, who = {}) =>
812 rpc({ jsonrpc: "2.0", id: 9, method: "tools/call", params: { name, arguments: args } }, who);
813 expect((await call("this_week", {})).result.isError).toBe(true);
814 const items = JSON.parse((await call("this_week", {}, week)).result.content[0].text);
815 const late = items.find((i: any) => i.address.startsWith("77 Harbor View") && i.deadline.label === "Inspection period ends");
816 expect(late.owner.role).toBe("Buyer");
817 expect(items.every((i: any) => i.deadline.done_at === null)).toBe(true);
818 // What data-live refetches is this same section: once the date is done it is gone from it.
819 const card = async () => {
820 const page = await (await api("/", {}, week)).text();
821 return page.slice(page.indexOf('id="week"'), page.indexOf('id="today"'));
822 };
823 expect(await card()).toContain(`popovertarget="sheet-${late.deadline.id}"`);
824 await call("mark_done", { id: late.deadline.id }, week);
825 expect(await card()).not.toContain(`popovertarget="sheet-${late.deadline.id}"`);
826 });
src/terminal.test.ts +23
@@ -265,6 +265,29 @@ test("n declines a reminder with a reason, u undoes it; anon is not asked to typ
265265 expect(db.query<{ n: number }, []>("SELECT count(*) AS n FROM reminder_declined").get()!.n).toBe(before);
266266 });
267267
268 test("w lists the dates overdue or due within seven days, by day, with who owes each; x works there", () => {
269 const soon = addDeadline(db, alice, { dealId: id, label: "Week check", due: addDays(today(), 2), owes: "buyer" });
270 if (!soon.ok) throw new Error(soon.message);
271 const t = terminal(db, alice, context);
272 t.press("w");
273 const shown = lines(t);
274 expect(shown.join("\n")).toContain("[w] this week");
275 const owed = shown.find((l) => l.includes("Week check — 12 Elm St"))!;
276 expect(owed).toContain("Ann Buyer");
277 // The closing is 45 days out: outside the window.
278 expect(shown.join("\n")).not.toContain("Closing — 12 Elm St");
279 expect(shown.some((l) => /^[A-Z][a-z]{2}, [A-Z][a-z]{2} \d+$/.test(l))).toBe(true);
280 while (!under(t).includes("Week check — 12 Elm St")) t.press("j");
281 t.press("x");
282 expect(lines(t).join("\n")).not.toContain("Week check — 12 Elm St");
283 });
284
285 test("a guest sees no deals in the week view", () => {
286 const t = terminal(db, { role: "anon" } as Who, context);
287 t.press("w");
288 expect(lines(t).join("\n")).toContain("Sign in to see deals.");
289 });
290
268291 test("s on a deal lists what was sent, newest first, with the words; b comes back; a guest sees nothing", () => {
269292 const inspection = date("inspection");
270293 const [buyer, seller] = deal().parties;
src/terminal.ts +23 −4
@@ -4,6 +4,7 @@
44 * a pty; a test presses keys and reads the screen. Three views:
55 *
66 * dates every open date of every deal, soonest first (h shows done ones)
7 * week the open dates overdue or due in the next seven days, by day
78 * reminders what goes out today; enter reads a draft, e edits its words, s sends it
89 * deal one deal's dates and parties; a adds a date, p a party, D removes it
910 *
@@ -44,6 +45,7 @@ import { PARTY_LABEL, PARTY_ROLES, type PartyRole } from "./deadlines.ts";
4445 import { drafts, MOMENT_LABEL, unsent, type Agent, type Draft } from "./reminders.ts";
4546 import type { Result } from "./result.ts";
4647 import type { Who } from "./who.ts";
48 import { owner, thisWeek } from "./week.ts";
4749
4850 const esc = "\x1b[";
4951 const dim = (s: string): string => `${esc}2m${s}${esc}0m`;
@@ -51,7 +53,7 @@ const bold = (s: string): string => `${esc}1m${s}${esc}0m`;
5153 const COLOUR: Readonly<Record<Urgency, string>> = { overdue: "31", soon: "33", later: "36", done: "2" };
5254 const tint = (u: Urgency, s: string): string => `${esc}${COLOUR[u]}m${s}${esc}0m`;
5355
54 type View = "dates" | "reminders" | "deal" | "messages";
56 type View = "dates" | "week" | "reminders" | "deal" | "messages";
5557 interface Row {
5658 readonly deal: DealView;
5759 readonly date: DeadlineView;
@@ -104,6 +106,7 @@ export function terminal(
104106 const deal = openDeal();
105107 return deal === undefined ? [] : deal.deadlines.map((date) => ({ deal, date }));
106108 }
109 if (view === "week") return thisWeek(deals(), on()).map(({ deal, deadline }) => ({ deal, date: deadline }));
107110 return deals()
108111 .flatMap((deal) =>
109112 deal.deadlines.filter((d) => showDone || d.done_at === null).map((date) => ({ deal, date })),
@@ -345,6 +348,9 @@ export function terminal(
345348 } else if (key === "d" || key === "b" || key === "\x1b") {
346349 view = "dates";
347350 cursor = 0;
351 } else if (key === "w") {
352 view = "week";
353 cursor = 0;
348354 } else if (key === "r") {
349355 view = "reminders";
350356 cursor = 0;
@@ -381,7 +387,8 @@ export function terminal(
381387 const { date, deal } = row;
382388 const u = urgency(date.due, on(), date.done_at !== null);
383389 const when = tint(u, `${spoken(date.due).padEnd(12)} ${(date.done_at === null ? relative(date.due, on()) : "done").padEnd(12)}`);
384 const text = withDeal ? `${date.label} — ${deal.address}` : date.label;
390 const who = owner(deal, date);
391 const text = view === "week" ? `${date.label} — ${deal.address} · ${who.name ?? who.role}` : withDeal ? `${date.label} — ${deal.address}` : date.label;
385392 const moved = date.moves.length > 0 ? dim(` moved: ${date.moves.at(-1)!.reason}`) : "";
386393 return `${i === cursor ? "▸" : " "} ${when} ${i === cursor ? bold(text) : text}${moved}`;
387394 };
@@ -392,7 +399,7 @@ export function terminal(
392399 const lines = [
393400 `${bold(context.title)} ${context.agent.name}, ${context.agent.brokerage} ${dim(context.where)} ${dim(me.role === "anon" ? "guest" : `${me.name}${me.role === "admin" ? " (admin)" : ""}`)}`,
394401 context.ssh === undefined ? dim("The terminal is off.") : dim(`connect: ${context.ssh}`),
395 `${spoken(day)} · ${all.length} deals · ${view === "dates" ? bold("[d] dates") : "[d] dates"} · ${view === "reminders" ? bold("[r] reminders today") : "[r] reminders today"}`,
402 `${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"}`,
396403 "",
397404 ];
398405 if (view === "dates") {
@@ -401,6 +408,18 @@ export function terminal(
401408 if (!listed.ok) lines.push(listed.message);
402409 else if (rows.length === 0) lines.push(dim("Nothing open. Every date is done."));
403410 rows.forEach((row, i) => lines.push(dateLine(row, i, true)));
411 } else if (view === "week") {
412 const rows = dateRows();
413 const listed = listDeals(db, me);
414 if (!listed.ok) lines.push(listed.message);
415 else if (rows.length === 0) lines.push(dim("Nothing due in the next seven days."));
416 let heading = "";
417 rows.forEach((row, i) => {
418 const h = row.date.due < day ? "Overdue" : row.date.due === day ? "Today" : spoken(row.date.due);
419 if (h !== heading) lines.push(bold(h));
420 heading = h;
421 lines.push(dateLine(row, i, true));
422 });
404423 } else if (view === "messages") {
405424 const deal = openDeal();
406425 if (deal === undefined) lines.push(dim("That deal is gone."));
@@ -451,7 +470,7 @@ export function terminal(
451470 ? "j/k move · enter read · b back to the deal · d dates · q quit"
452471 : view === "deal"
453472 ? "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"
454 : `j/k move · x done · u reopen · m move · o open deal · n new deal · c check dates · h ${showDone ? "hide" : "show"} done · r reminders · q quit`;
473 : `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`;
455474 lines.push(dim(me.role === "anon" ? `${keys} · sign in with a key the forge knows to change anything` : keys));
456475 }
457476 return lines;
src/week.test.ts added +33
@@ -0,0 +1,33 @@
1 import { expect, test } from "bun:test";
2 import { thisWeek } from "./week.ts";
3
4 const on = "2026-11-02";
5 const d = (due: string, done: string | null = null) => ({ due, done_at: done });
6 const deals = [
7 { address: "B Street", deadlines: [d("2026-11-09"), d("2026-11-10"), d("2026-10-30")] },
8 { address: "A Street", deadlines: [d("2026-11-09"), d("2026-11-03", "2026-11-01"), d("2026-11-02")] },
9 ];
10
11 test("the window runs from overdue to day seven, and no further", () => {
12 const dues = thisWeek(deals, on).map((i) => i.deadline.due);
13 expect(dues).toContain("2026-11-09");
14 expect(dues).not.toContain("2026-11-10");
15 expect(dues).toContain("2026-10-30");
16 });
17
18 test("done dates are left out", () => {
19 expect(thisWeek(deals, on).some((i) => i.deadline.done_at !== null)).toBe(false);
20 });
21
22 test("overdue first, then by due date, then by address", () => {
23 expect(thisWeek(deals, on).map((i) => [i.deadline.due, i.deal.address])).toEqual([
24 ["2026-10-30", "B Street"],
25 ["2026-11-02", "A Street"],
26 ["2026-11-09", "A Street"],
27 ["2026-11-09", "B Street"],
28 ]);
29 });
30
31 test("nothing in the window is an empty list", () => {
32 expect(thisWeek([], on)).toEqual([]);
33 });
src/week.ts added +43
@@ -0,0 +1,43 @@
1 /**
2 * The dates to chase this week: every open date that is overdue or falls
3 * within the next seven days, oldest first, then by address.
4 */
5
6 import { addDays } from "./dates.ts";
7 import { PARTY_LABEL, type PartyRole } from "./deadlines.ts";
8
9 /** How many days past today still count as this week. */
10 export const WEEK = 7;
11
12 export interface WeekDeal<D> {
13 readonly address: string;
14 readonly deadlines: readonly D[];
15 }
16
17 export interface WeekItem<Deal, D> {
18 readonly deal: Deal;
19 readonly deadline: D;
20 }
21
22 export function thisWeek<D extends { due: string; done_at: string | null }, Deal extends WeekDeal<D>>(
23 deals: readonly Deal[],
24 on: string,
25 ): WeekItem<Deal, D>[] {
26 const last = addDays(on, WEEK);
27 return deals
28 .flatMap((deal) =>
29 deal.deadlines.filter((d) => d.done_at === null && d.due <= last).map((deadline) => ({ deal, deadline })),
30 )
31 .sort(
32 (a, b) =>
33 a.deadline.due.localeCompare(b.deadline.due) || a.deal.address.localeCompare(b.deal.address),
34 );
35 }
36
37 /** Who owes a date: the deal's party in that role by name, if it has one, and the role either way. */
38 export function owner(
39 deal: { readonly parties: readonly { role: PartyRole; name: string }[] },
40 d: { readonly owes: PartyRole },
41 ): { name: string | undefined; role: string } {
42 return { name: deal.parties.find((p) => p.role === d.owes)?.name, role: PARTY_LABEL[d.owes] };
43 }
static/app.css +36
@@ -745,3 +745,39 @@ textarea.input {
745745 min-height: calc(var(--size-tap) * 2);
746746 resize: vertical;
747747 }
748
749 /* This week: open dates by day, one row each, readable at 360px. */
750 .week-day {
751 margin: var(--space-4) 0 var(--space-1);
752 font-size: var(--text-sm);
753 color: var(--color-muted);
754 }
755 .week-list {
756 list-style: none;
757 margin: 0;
758 padding: 0;
759 }
760 .week-row {
761 display: flex;
762 align-items: center;
763 justify-content: space-between;
764 gap: var(--space-3);
765 width: 100%;
766 min-height: var(--size-tap);
767 padding: var(--space-2) 0;
768 font: inherit;
769 color: inherit;
770 text-align: left;
771 background: none;
772 border: 0;
773 border-bottom: 1px solid var(--color-line);
774 cursor: pointer;
775 }
776 .week-what {
777 display: grid;
778 min-width: 0;
779 overflow-wrap: anywhere;
780 }
781 .week-row .badge {
782 flex: none;
783 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs