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

When a lead's last follow-up has gone out with no answer, the desk says so and one tap marks them lost (never answered) #88

Merged opened this

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

Merged

mason/speed-to-lead:mason/69-when-a-lead-s-last-follow-up-has-gone-ou → main 3 commits fork

  • Merged. mason/69-when-a-lead-s-last-follow-up-has-gone-ou was merged into main as eac5100.

Review

Sign in to review this change.
14 files changed +301 −21
README.md +12
@@ -131,6 +131,18 @@ samples (step 1).
131131
132132 ## How it works
133133
134 **When follow-ups run out.** A lead that is still new or contacted, whose
135 every follow-up (on its own schedule, whatever cadence the agent chose) has
136 gone out or been set aside, and who has never written back, been called or had
137 a showing booked, shows "Follow-ups finished — no answer" on its desk row and
138 its page (`followUpsFinished`, `src/finished.ts`). The row offers one button,
139 "Mark lost — never answered": it posts to `/leads/:id/state` with the
140 `never_answered` reason, so it is the same action, `permit` check and Activity
141 entry as marking lost by hand, and nothing is sent to the lead. The
142 terminal says the same on the desk and lead screen, and `m` on the lead screen
143 does the same one thing (hidden for anyone `permit` would refuse). No new
144 permission cell. The sample desk includes one such lead (Ruth Okafor).
145
134146 **Sample inquiries** arrive on demand from the desk button, `POST
135147 /sample/inquiry` (JSON, 201), the MCP `new_sample_inquiry` tool, or `i` in the
136148 terminal desk. They go through the same path as `POST /leads`, for anyone who
docs/design/areas/desk.md +9
@@ -29,3 +29,12 @@ link; `.lead-item` is a two-column grid (the row, then the star). On a lead's
2929 page the same form sits under the name. The button is `--size-tap` (44px)
3030 square on every screen, so it is a thumb-sized target on a phone, and it
3131 works as a plain POST with no JavaScript.
32
33 # Desk: a lead the follow-ups have finished with
34
35 `.status[data-finished]` reads "Follow-ups finished — no answer". Under the
36 row, `.close-out` is a form holding one `.button.button-quiet` ("Mark lost —
37 never answered"), padded to line up with the row; it sits beside the row's
38 link inside `li.lead-item` (full width under the row, shown to whoever
39 sees the star), never inside it. On the lead's page the same form leads
40 `.states`, as a plain `.button`.
src/actions.test.ts +2 −2
@@ -226,10 +226,10 @@ test("qualified or lost leaves the cadence", () => {
226226 if (!gone.ok) expect(gone.error).toBe("not_found");
227227 });
228228
229 test("the sample desk: fifteen leads, some red, some mid-cadence; only an admin restarts it", () => {
229 test("the sample desk: sixteen leads, some red, some mid-cadence; only an admin restarts it", () => {
230230 const sampleDb = openDb(mkdtempSync(join(tmpdir(), "app-sample-")));
231231 expect(resetSample(sampleDb, alice).ok).toBe(false);
232 expect(must(resetSample(sampleDb, root, T0)).leads).toBe(15);
232 expect(must(resetSample(sampleDb, root, T0)).leads).toBe(16);
233233 const listed = must(listLeads(sampleDb, alice, { now: T0.getTime() }));
234234 // A believable first record: 14 leads in 30 days, 57% answered or waiting under 5 minutes.
235235 expect(listed.record).toMatchObject({ leads: 14, replied: 7, within_5_min_pct: 57 });
src/export.test.ts +1 −1
@@ -56,7 +56,7 @@ test("the download has the header, one row per lead, and the file headers", asyn
5656 expect(rows[0]).toEqual([...COLUMNS]);
5757 const all = await (await get("/leads")).json();
5858 expect(rows.length).toBe(1 + all.leads.length);
59 expect(all.leads.length).toBe(15);
59 expect(all.leads.length).toBe(16);
6060 expect(rows[1]!.length).toBe(COLUMNS.length);
6161 expect(["yes", "no"]).toContain(rows[1]![9]!);
6262 expect(["open", "qualified", "lost"]).toContain(rows[1]![4]!);
src/finished.test.ts added +133
@@ -0,0 +1,133 @@
1 /**
2 * A lead whose follow-ups have all gone out with no answer says so on the
3 * desk and on its page, and one tap marks it lost (never answered). A reply,
4 * a call or a showing keeps it from being flagged; the cadence is the lead's own.
5 */
6 import { expect, test } from "bun:test";
7 import { mkdtempSync } from "node:fs";
8 import { tmpdir } from "node:os";
9 import { join } from "node:path";
10 import { activity, addLead, bookShowing, getLead, listLeads, logCall, logLeadReply, sendReply, setState, skipFollowUp, type Result } from "./actions.ts";
11 import { openDb } from "./db.ts";
12 import { advance } from "./leads.ts";
13 import { deskPage } from "./pages/desk.ts";
14 import { leadPage } from "./pages/lead.ts";
15 import { FINISHED_ACTION, FINISHED_LABEL } from "./finished.ts";
16 import { currentAgent, storeAgent } from "./profile.ts";
17 import { SAMPLES, seed } from "./sample.ts";
18 import type { Who } from "./who.ts";
19
20 const alice: Who = { role: "user", id: "u1", name: "alice" };
21 const anon: Who = { role: "anon" };
22 const T0 = new Date("2026-03-01T10:00:00Z");
23 const DAY = 86_400_000;
24 const at = (days: number) => new Date(T0.getTime() + days * DAY);
25 const must = <T>(r: Result<T>): T => {
26 if (!r.ok) throw new Error(r.message);
27 return r.value;
28 };
29 const fresh = () => openDb(mkdtempSync(join(tmpdir(), "app-finished-")));
30 let n = 0;
31 const arrive = (db: ReturnType<typeof fresh>) => {
32 const l = must(
33 addLead(db, alice, { name: `Ana ${++n}`, email: `a${n}@example.com`, phone: `(206) 555-${String(1000 + n)}`, source: "website", message: "Is 12 Oak St open?", consent: false }, T0),
34 );
35 must(sendReply(db, alice, { id: l.id }, T0));
36 return l.id;
37 };
38 /** Send every follow-up on its day, as the agent approving each. */
39 const runCadence = (db: ReturnType<typeof fresh>, id: number, last: number) => {
40 for (let d = 1; d <= last; d++) {
41 advance(db, at(d).toISOString());
42 const lead = must(getLead(db, alice, { id }));
43 const due = lead.messages.find((m) => m.status === "due");
44 if (due !== undefined) must(sendReply(db, alice, { id }, at(d)));
45 }
46 };
47 const flagged = (db: ReturnType<typeof fresh>, id: number) => must(getLead(db, alice, { id })).finished;
48 const onDesk = (db: ReturnType<typeof fresh>, id: number) => must(listLeads(db, alice, {})).leads.find((l) => l.id === id)!.finished;
49
50 test("flagged once every follow-up has gone out, not before", () => {
51 const db = fresh();
52 const id = arrive(db);
53 runCadence(db, id, 14);
54 expect(flagged(db, id)).toBe(false);
55 expect(onDesk(db, id)).toBe(false);
56 runCadence(db, id, 31);
57 expect(flagged(db, id)).toBe(true);
58 expect(onDesk(db, id)).toBe(true);
59 });
60
61 test("a skipped follow-up counts as finished, and a custom cadence is the lead's own", () => {
62 const db = fresh();
63 storeAgent(db, { ...currentAgent(db), cadence: [2, 5] }, "test", T0.toISOString());
64 const id = arrive(db);
65 const first = must(getLead(db, alice, { id })).messages.find((m) => m.day === 5)!;
66 must(skipFollowUp(db, alice, { id, messageId: first.id }, at(1)));
67 runCadence(db, id, 2);
68 expect(flagged(db, id)).toBe(true);
69 });
70
71 test("never flagged after a reply, a call or a showing", () => {
72 const db = fresh();
73 const replied = arrive(db);
74 const called = arrive(db);
75 const showing = arrive(db);
76 const fine = arrive(db);
77 for (const id of [replied, called, showing, fine]) runCadence(db, id, 31);
78 must(logLeadReply(db, alice, { id: replied, body: "Still looking!", channel: "email" }, at(32)));
79 must(sendReply(db, alice, { id: replied }, at(32)));
80 must(logCall(db, alice, { id: called, outcome: "no_answer" }, at(32)));
81 must(bookShowing(db, alice, { id: showing, when: "2026-04-20T10:00", address: "12 Oak St" }, at(32)));
82 expect(flagged(db, replied)).toBe(false);
83 expect(flagged(db, called)).toBe(false);
84 expect(flagged(db, showing)).toBe(false);
85 expect(flagged(db, fine)).toBe(true);
86 for (const id of [replied, called, showing]) expect(onDesk(db, id)).toBe(false);
87 expect(onDesk(db, fine)).toBe(true);
88 });
89
90 test("the desk row and the lead page say so in plain words, with the one button", () => {
91 const db = fresh();
92 const id = arrive(db);
93 runCadence(db, id, 31);
94 const desk = must(listLeads(db, alice, {})).leads;
95 const row = deskPage({ who: alice, agent: currentAgent(db), leads: desk, mayAdd: true, mayStar: true, mayReset: false });
96 expect(row).toContain(FINISHED_LABEL);
97 expect(row).toContain(`action="/leads/${id}/state"`);
98 expect(row).toContain('name="reason" value="never_answered"');
99 expect(row).toContain(FINISHED_ACTION);
100 const noButton = deskPage({ who: anon, agent: currentAgent(db), leads: desk, mayAdd: false, mayStar: false, mayReset: false });
101 expect(noButton).toContain(FINISHED_LABEL);
102 expect(noButton).not.toContain(FINISHED_ACTION);
103 const page = leadPage({ who: alice, agent: currentAgent(db), lead: must(getLead(db, alice, { id })), mayUpdate: true, next: null, now: at(32).getTime() });
104 expect(page).toContain(FINISHED_LABEL);
105 expect(page).toContain(FINISHED_ACTION);
106 });
107
108 test("the action marks it lost, never answered, sends nothing, and Activity lists it", () => {
109 const db = fresh();
110 const id = arrive(db);
111 runCadence(db, id, 31);
112 const sent = () => db.query<{ n: number }, []>("SELECT count(*) AS n FROM message WHERE status = 'sent'").get()!.n;
113 const before = sent();
114 const lost = must(setStateFor(db, id));
115 expect(lost).toMatchObject({ state: "lost", lostReason: "never_answered", finished: false });
116 expect(sent()).toBe(before);
117 const root: Who = { role: "admin", id: "u0", name: "root" };
118 const trail = must(activity(db, root, {}));
119 expect(trail.lost).toEqual([{ reason: "never_answered", count: 1 }]);
120 expect(JSON.stringify(trail.rows)).toContain("lost");
121 expect(setStateFor(db, id, anon).ok).toBe(false);
122 });
123
124 test("the sample data holds one such lead", () => {
125 const db = fresh();
126 seed(db, new Date());
127 const desk = must(listLeads(db, alice, {})).leads;
128 expect(desk.filter((l) => l.finished).map((l) => l.name)).toEqual(["Ruth Okafor"]);
129 expect(SAMPLES.some((s) => s.name === "Ruth Okafor")).toBe(true);
130 });
131
132 const setStateFor = (db: ReturnType<typeof fresh>, id: number, who: Who = alice) =>
133 setState(db, who, { id, state: "lost", reason: "never_answered" });
src/finished.ts added +35
@@ -0,0 +1,35 @@
1 /**
2 * A lead the follow-ups have finished with: every follow-up on its own
3 * schedule has gone out (or been set aside), and nobody has answered.
4 * Plain data in, a yes or no out; the schedule is the lead's own, so it
5 * holds for any cadence the agent chose.
6 */
7
8 import { CHECK_IN_DAY } from "./drafts.ts";
9 import type { Lead } from "./leads.ts";
10
11 /** What the desk says of such a lead, in the agent's words. */
12 export const FINISHED_LABEL = "Follow-ups finished — no answer";
13
14 /** What the one-tap button says. */
15 export const FINISHED_ACTION = "Mark lost — never answered";
16
17 /**
18 * True when the lead is still new or contacted, was replied to, is not put
19 * away, has no showing, has never written back or been called, and every
20 * message it has is sent or skipped with at least one follow-up among them.
21 * A check-in, a showing's note or an answer to a reply is not a follow-up
22 * on the cadence, so a lead with one is never flagged.
23 */
24 export function followUpsFinished(
25 lead: Pick<Lead, "state" | "replied_at" | "back_on">,
26 messages: readonly { readonly day: number; readonly status: string }[],
27 heardFrom: boolean,
28 showing: boolean,
29 ): boolean {
30 if (lead.state !== "new" && lead.state !== "contacted") return false;
31 if (lead.replied_at === null || lead.back_on !== null || heardFrom || showing) return false;
32 if (!messages.every((m) => m.status === "sent" || m.status === "skipped")) return false;
33 if (messages.some((m) => m.day >= CHECK_IN_DAY)) return false;
34 return messages.some((m) => m.day > 0);
35 }
src/leads.ts +46 −9
@@ -38,6 +38,7 @@ import { between, GREEN_MS } from "./clock.ts";
3838 import type { Agent } from "./env.ts";
3939 import { isQuiet, nextOpening } from "./quiet.ts";
4040 import { type LostReason } from "./lost.ts";
41 import { followUpsFinished } from "./finished.ts";
4142 import { morningOn } from "./putaway.ts";
4243 import { clockTime, dayName, holdUntil, morningAfter, morningBefore, type Showing } from "./showings.ts";
4344
@@ -114,6 +115,8 @@ export interface LeadDetail extends Lead {
114115 readonly calls: readonly Call[];
115116 /** The showing booked on this lead; null when none. */
116117 readonly showing: Showing | null;
118 /** Every follow-up has gone out or been set aside and no one answered: the agent may close it out. */
119 readonly finished: boolean;
117120 }
118121
119122 /** When the lead began to wait on our answer to what they wrote back; null when no answer is owed. */
@@ -130,6 +133,8 @@ export interface DeskLead extends Lead {
130133 readonly goes_at: string | null;
131134 /** The showing booked on this lead, if one is. */
132135 readonly showing: Pick<Showing, "at" | "address" | "hold_until"> | null;
136 /** Every follow-up has gone out or been set aside and no one answered. */
137 readonly finished: boolean;
133138 }
134139
135140 /**
@@ -288,15 +293,19 @@ export const showingsAhead = (db: Database, now: number): Ahead[] =>
288293
289294 export function detail(db: Database, id: number): LeadDetail | null {
290295 const found = findLead(db, id);
291 return found === null
292 ? null
293 : {
294 ...found,
295 messages: messagesOf(db, id),
296 replies: repliesOf(db, id),
297 calls: callsOf(db, id),
298 showing: showingOf(db, id),
299 };
296 if (found === null) return null;
297 const messages = messagesOf(db, id);
298 const replies = repliesOf(db, id);
299 const calls = callsOf(db, id);
300 const showing = showingOf(db, id);
301 return {
302 ...found,
303 messages,
304 replies,
305 calls,
306 showing,
307 finished: followUpsFinished(found, messages, replies.length + calls.length > 0, showing !== null),
308 };
300309 }
301310
302311 export const MAX_QUERY = 80;
@@ -341,6 +350,7 @@ const DIGITS = ["(", ")", "-", " ", ".", "+"].reduce(
341350 * note holds it, or whose phone holds its digits ("555 0101" finds "(206) 555-0101").
342351 */
343352 export function desk(db: Database, limit: number, q = ""): DeskLead[] {
353 const finishedIds = finishedLeads(db);
344354 const digits = /^[\d\s()+.\-]+$/.test(q) ? q.replace(/\D/g, "") : "";
345355 return db
346356 .query<
@@ -374,6 +384,7 @@ export function desk(db: Database, limit: number, q = ""): DeskLead[] {
374384 .all(limit, q === "" ? "" : likeOf(q), digits === "" ? "" : `%${digits}%`)
375385 .map(({ ready_id, ready_day, ready_since, next_at, goes_at, show_at, show_address, show_hold, ...row }) => ({
376386 ...lead(row),
387 finished: finishedIds.has(row.id),
377388 ready:
378389 ready_id === null || ready_day === null || ready_since === null
379390 ? null
@@ -387,6 +398,32 @@ export function desk(db: Database, limit: number, q = ""): DeskLead[] {
387398 }));
388399 }
389400
401 /** The ids of leads whose follow-ups have finished with no answer (see `followUpsFinished`), for the whole desk at once. */
402 function finishedLeads(db: Database): Set<number> {
403 const rows = db
404 .query<
405 Pick<Lead, "state" | "replied_at" | "back_on"> & { id: number; day: number | null; status: string | null; heard: number; booked: number },
406 []
407 >(
408 `SELECT lead.id AS id, lead.state AS state, lead.replied_at AS replied_at, lead.back_on AS back_on,
409 message.day AS day, message.status AS status,
410 (EXISTS (SELECT 1 FROM inbound WHERE lead_id = lead.id) OR EXISTS (SELECT 1 FROM phone_call WHERE lead_id = lead.id)) AS heard,
411 EXISTS (SELECT 1 FROM showing WHERE lead_id = lead.id) AS booked
412 FROM lead LEFT JOIN message ON message.lead_id = lead.id
413 WHERE lead.state IN ('new', 'contacted') AND lead.replied_at IS NOT NULL`,
414 )
415 .all();
416 const byLead = new Map<number, typeof rows>();
417 for (const r of rows) byLead.set(r.id, [...(byLead.get(r.id) ?? []), r]);
418 const found = new Set<number>();
419 for (const [id, mine] of byLead) {
420 const first = mine[0]!;
421 const messages = mine.flatMap((r) => (r.day === null || r.status === null ? [] : [{ day: r.day, status: r.status }]));
422 if (followUpsFinished(first, messages, first.heard === 1, first.booked === 1)) found.add(id);
423 }
424 return found;
425 }
426
390427 /** The lead that needs the agent next, and since when it has. */
391428 export interface NextLead {
392429 readonly id: number;
src/pages/desk.ts +10 −1
@@ -8,6 +8,7 @@ import { deskTitle, layout } from "./layout.ts";
88 import { escape } from "../http.ts";
99 import { recordLine, sourceLine } from "../clock.ts";
1010 import { isAfterShowing, isBeforeShowing, isAnswer, isCheckIn } from "../drafts.ts";
11 import { FINISHED_ACTION, FINISHED_LABEL } from "../finished.ts";
1112 import { dateName } from "../putaway.ts";
1213 import { goesLabel, RECORD_NOTE } from "../quiet.ts";
1314 import { MAX_ADDRESS, MAX_LISTED, showingWhen } from "../showings.ts";
@@ -208,9 +209,17 @@ function status(lead: DeskLead, now: number, zone: string): string {
208209 return `<span class="status">Put away until ${escape(dateName(lead.back_on))}</span>`;
209210 if (lead.next_at !== null)
210211 return `<span class="status">Next follow-up ${escape(day(held(lead, lead.next_at), zone))}</span>`;
212 if (lead.finished) return `<span class="status" data-finished>${FINISHED_LABEL}</span>`;
211213 return `<span class="status">Follow-ups done</span>`;
212214 }
213215
216 /** The one tap that closes a finished lead out: the same lost-with-a-reason post as the lead's page; nothing is sent. */
217 const closeOut = (lead: DeskLead, may: boolean): string =>
218 !lead.finished || !may
219 ? ""
220 : `
221 <form class="close-out" method="post" action="/leads/${lead.id}/state"><input type="hidden" name="state" value="lost"><input type="hidden" name="reason" value="never_answered"><button class="button button-quiet">${FINISHED_ACTION}</button></form>`;
222
214223 const row = (lead: DeskLead, now: number, zone: string, back?: string): string => `<li class="lead-item">
215224 <a class="lead-row" href="/leads/${lead.id}"${lead.state === "lost" ? " data-closed" : ""}>
216225 <span class="lead-main">
@@ -222,7 +231,7 @@ const row = (lead: DeskLead, now: number, zone: string, back?: string): string =
222231 </span>
223232 ${clock(lead, now, lead.ready !== null && isAnswer(lead.ready.day) ? lead.ready.since : null)}
224233 </a>${back === undefined ? "" : `
225 ${starForm(lead, back)}`}
234 ${starForm(lead, back)}`}${closeOut(lead, back !== undefined)}
226235 </li>`;
227236
228237 const pasteForm = `<details class="card add">
src/pages/lead.ts +10 −2
@@ -17,6 +17,7 @@ import { answerSince, MAX_INBOUND, MAX_LEAD_NOTE, type LeadDetail, type Message,
1717 import type { Agent } from "../env.ts";
1818 import type { Who } from "../who.ts";
1919 import { layout } from "./layout.ts";
20 import { FINISHED_ACTION, FINISHED_LABEL } from "../finished.ts";
2021 import { LOST_REASONS, REASON_LABEL, lostSaid } from "../lost.ts";
2122 import { clock, consent, day, source, starForm, STATE_LABEL, when } from "./parts.ts";
2223
@@ -90,7 +91,9 @@ export function leadPage(input: {
9091 : `Marked ${STATE_LABEL[lead.state].toLowerCase()}: out of the follow-up plan.`
9192 : lead.messages.some((m) => m.status === "scheduled")
9293 ? "The next follow-up is drafted below and comes due on its day."
93 : "Every follow-up has gone out."
94 : lead.finished
95 ? `${FINISHED_LABEL}. Every follow-up has gone out and they have not answered.`
96 : "Every follow-up has gone out."
9497 }</p></div>`
9598 : `<div class="pane ours ready">
9699 <h2>${titleOf(ready)} <span class="muted">· by ${CHANNEL[ready.channel]}</span></h2>
@@ -192,7 +195,12 @@ export function leadPage(input: {
192195
193196 const states =
194197 mayUpdate && !closed
195 ? `<section class="states">
198 ? `<section class="states">${
199 lead.finished
200 ? `
201 <form class="close-out" method="post" action="${path}/state"><input type="hidden" name="state" value="lost"><input type="hidden" name="reason" value="never_answered"><button class="button">${FINISHED_ACTION}</button></form>`
202 : ""
203 }
196204 <form method="post" action="${path}/state"><input type="hidden" name="state" value="qualified"><button class="button button-quiet">Mark qualified</button></form>
197205 <form method="post" action="${path}/state"><input type="hidden" name="state" value="lost">
198206 <label>Why? <select name="reason" required>${LOST_REASONS.map((r) => `<option value="${r}">${escape(REASON_LABEL[r])}</option>`).join("")}</select></label>
src/sample.ts +1
@@ -86,6 +86,7 @@ export const SAMPLES: readonly Sample[] = [
8686 person("Owen Hart", "zillow", false, "Is 55 Cedar Ln still on the market? We'd like a second showing.", { ago: 9 * D, answeredIn: 2 * M + 40 * S, touched: [1, 3], closed: { state: "lost", reason: "bought_elsewhere" } }),
8787 person("Nadia Petrov", "website", true, "We might sell, but not before our kids finish school in two years. What should we do now?", { ago: 12 * D, answeredIn: 3 * M + 5 * S, touched: [1, 3], closed: { state: "lost", reason: "not_ready" } }),
8888 person("Carl Dunn", "referral", false, "A friend gave me your name. Call me about listing the duplex.", { ago: 20 * D, answeredIn: 5 * M, touched: [1, 3, 7], closed: { state: "lost", reason: "never_answered" } }),
89 person("Ruth Okafor", "website", false, "Looking at starter homes under $400k. Can you send a few options?", { ago: 34 * D, answeredIn: 2 * M + 10 * S, touched: [1, 3, 7, 14, 30] }),
8990 ];
9091
9192 /** Lay the samples out as of `now`. Returns how many. */
src/search.test.ts +2 −2
@@ -37,8 +37,8 @@ test("a name, an email or a phone finds the lead, in any case", () => {
3737 });
3838
3939 test("no search is the whole desk", () => {
40 expect(names({}).length).toBe(15);
41 expect(names({ q: "" }).length).toBe(15);
40 expect(names({}).length).toBe(16);
41 expect(names({ q: "" }).length).toBe(16);
4242 });
4343
4444 test("a search combines with the view", () => {
src/terminal.test.ts +26 −1
@@ -412,7 +412,7 @@ test("x on the desk shows the leads as CSV, for those who may list; esc goes bac
412412 const t = terminal(db, alice);
413413 t.key("x");
414414 const screen = read(t);
415 expect(screen).toContain("15 leads as CSV");
415 expect(screen).toContain("16 leads as CSV");
416416 expect(screen).toContain("name,email,phone,source,status");
417417 expect(screen).toContain("Maria Gonzalez");
418418 t.key("\x1b");
@@ -546,3 +546,28 @@ test("the terminal shows the follow-up days, an admin edits them, a bad list cha
546546 expect(read(user)).not.toContain("editing");
547547 expect(days()).toBe("[2,5,10]");
548548 });
549
550 test("a lead whose follow-ups finished says so, and m marks it lost, never answered; a guest cannot", () => {
551 const db = fresh();
552 const t = terminal(db, alice);
553 expect(read(t)).toContain("Follow-ups finished — no answer");
554 t.key("/");
555 type(t, "Ruth");
556 t.key("\r");
557 t.key("\r");
558 const screen = read(t);
559 expect(screen).toContain("Follow-ups finished — no answer");
560 expect(screen).toContain("m mark lost — never answered");
561 const id = (listLeads(db, alice) as { ok: true; value: { leads: { id: number; name: string }[] } }).value.leads.find((l) => l.name === "Ruth Okafor")!.id;
562 const sent = () => db.query<{ n: number }, []>("SELECT count(*) AS n FROM message WHERE status = 'sent'").get()!.n;
563 const before = sent();
564 const stranger = terminal(db, { role: "anon" });
565 stranger.key("m");
566 expect(getLead(db, alice, { id })).toMatchObject({ value: { state: "contacted" } });
567 t.key("m");
568 expect(read(t)).toContain("Ruth Okafor: lost, never answered.");
569 expect(getLead(db, alice, { id })).toMatchObject({ value: { state: "lost", lostReason: "never_answered" } });
570 expect(sent()).toBe(before);
571 const guest = terminal(db, { role: "anon" });
572 expect(read(guest)).not.toContain("Follow-ups finished");
573 });
src/terminal.ts +10 −3
@@ -7,7 +7,7 @@
77 * Screens:
88 * desk j/k move · enter open · * star · f view (needs/open/closed/all) · / find by name, email, phone or note · n log a lead · v paste a lead email · o open house sign-ins · i new sample inquiry · p profile · a activity (admin) · R restart samples (admin) · esc quit
99 * lead s approve and send · e edit, then send · w they wrote back · ] next lead that needs you ·
10 * q qualified · x lost · t asked to stop texts · D remove (admin) · esc back
10 * q qualified · x lost · m lost, never answered (follow-ups finished) · t asked to stop texts · D remove (admin) · esc back
1111 * edit type; enter is a new line · ctrl-d approve and send · esc cancel
1212 * wrote type what they wrote · ctrl-t text/email (text only with consent) · ctrl-d record it and draft the answer · esc cancel
1313 * paste paste the notification email · ctrl-d read it, then check each field in the add screen (consent starts as n) · esc cancel
@@ -69,6 +69,7 @@ import { goesLabel, isQuiet, nextOpening, RECORD_NOTE } from "./quiet.ts";
6969 import { said as saidOf } from "./sentences.ts";
7070 import { SOURCE_LABEL, SOURCES, channelFor, dayLabel, isAfterShowing, isAnswer, isBeforeShowing, isCheckIn, planLabel, type Channel, type Source } from "./drafts.ts";
7171 import { ssh, title, where } from "./env.ts";
72 import { FINISHED_ACTION, FINISHED_LABEL } from "./finished.ts";
7273 import { LOST_REASONS, REASON_LABEL, lostSaid } from "./lost.ts";
7374 import { answerSince, CLOSED, MAX_QUERY, VIEWS, queryOf, type DeskLead, type LeadDetail, type Message, type View as DeskView } from "./leads.ts";
7475 import { when } from "./pages/parts.ts";
@@ -288,7 +289,7 @@ export function terminal(
288289 l.goes_at !== null
289290 ? dim(goesLabel(l.goes_at, now(), zone))
290291 : l.ready === null
291 ? dim(l.state === "qualified" || l.state === "lost" ? l.state : l.back_on !== null ? `back on ${dateName(l.back_on)}` : "")
292 ? dim(l.state === "qualified" || l.state === "lost" ? l.state : l.back_on !== null ? `back on ${dateName(l.back_on)}` : l.finished ? FINISHED_LABEL : "")
292293 : l.ready.day === 0
293294 ? "reply drafted"
294295 : isAnswer(l.ready.day)
@@ -387,7 +388,9 @@ export function terminal(
387388 ? `Marked ${l.state}${l.state === "lost" ? ` — ${lostSaid(l)}` : ""}: out of the follow-up plan.`
388389 : next !== undefined
389390 ? `Nothing to send now. ${titleOf(next)} comes due ${next.due_at.slice(0, 10)}.`
390 : "Every follow-up has gone out.",
391 : l.finished
392 ? `${FINISHED_LABEL}. Every follow-up has gone out and they have not answered.`
393 : "Every follow-up has gone out.",
391394 ),
392395 );
393396 } else {
@@ -452,6 +455,7 @@ export function terminal(
452455 ...(l.state === "qualified" || l.state === "lost"
453456 ? ["o put back in follow-ups"]
454457 : ["q qualified", "x lost"]),
458 ...(l.finished && mayEdit(l) ? [`m ${FINISHED_ACTION.toLowerCase()}`] : []),
455459 ...(mayEdit(l) ? ["d fix details"] : []),
456460 ...(mayNote(l) ? [l.note === "" ? "n add a note" : "n edit your note"] : []),
457461 ...(mayStar(l) ? [l.starred ? "* take the star off" : "* star"] : []),
@@ -860,6 +864,9 @@ export function terminal(
860864 } else if (input === "q") {
861865 const marked = setState(db, me, { id, state: "qualified" });
862866 said = marked.ok ? `${l.name}: ${marked.value.state}.` : marked.message;
867 } else if (input === "m" && l.finished) {
868 const marked = setState(db, me, { id, state: "lost", reason: "never_answered" });
869 said = marked.ok ? `${marked.value.name}: lost, ${REASON_LABEL.never_answered}.` : marked.message;
863870 } else if (input === "x" && !CLOSED.includes(l.state))
864871 view = { name: "lost", id };
865872 else if (input === "c" && l.phone !== "")
static/app.css +4
@@ -230,6 +230,10 @@ footer {
230230 .lead-row:hover {
231231 background: var(--color-bg);
232232 }
233 .close-out {
234 grid-column: 1 / -1;
235 padding: 0 var(--space-4) var(--space-3);
236 }
233237 .lead-row[data-closed] {
234238 opacity: 0.72;
235239 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs