From 1f28560400fd14391d4048a1499b0b6c8e539f41 Mon Sep 17 00:00:00 2001 From: Deodate-Lawson Date: Fri, 27 Nov 2026 17:48:10 -0500 Subject: [PATCH] Prospects: the fit check after research is not sent email addresses or phone numbers After a company is researched, the fit check judges it again on what research found: the dossier's summary, its risks and up to 20 evidence claims. With the no-model site reader those claims are sentences from the company's own website, and they carry its mailboxes and sometimes a phone number, so both went to the chat model with every check. The company's name, listing description, summary, risks and claims now pass through withoutContactDetails (new, distribution/redact.ts) at that one call, before the text is joined and cut to length: an email address becomes [email], a phone number [phone]. The dossier, its contact channels, the evidence and the published profile are stored and shown as before, and no other model call changes. Telling a phone number from a year, a price, a postcode, a date or an organisation number is the work: the rule and what it does not catch are in redact.ts and the changeset, with a test for each kind of number. Co-Authored-By: Claude Fable 5.2 --- .changeset/fit-check-contact-details.md | 30 ++ pipelines/src/distribution/redact.test.ts | 251 +++++++++++++++ pipelines/src/distribution/redact.ts | 185 +++++++++++ .../distribution/run.contact-details.test.ts | 303 ++++++++++++++++++ pipelines/src/distribution/run.ts | 10 +- 5 files changed, 776 insertions(+), 3 deletions(-) create mode 100644 .changeset/fit-check-contact-details.md create mode 100644 pipelines/src/distribution/redact.test.ts create mode 100644 pipelines/src/distribution/redact.ts create mode 100644 pipelines/src/distribution/run.contact-details.test.ts diff --git a/.changeset/fit-check-contact-details.md b/.changeset/fit-check-contact-details.md new file mode 100644 index 000000000..d1b3a9006 --- /dev/null +++ b/.changeset/fit-check-contact-details.md @@ -0,0 +1,30 @@ +--- +"@launchstack/pipelines": patch +--- + +The distribution pipeline's fit check after research no longer sends email +addresses or phone numbers to the chat model. `enrichCandidate` asks the fit +judge about each researched company with the company's name and listing +description, the dossier's summary, its risks and up to 20 evidence claims. +With the keyless site reader those claims are sentences from the company's own +website, and they carry its mailboxes and sometimes a phone number. Each of +those texts now passes through `withoutContactDetails` (new, in +`distribution/redact.ts`) before it is joined and cut to length: an email +address becomes `[email]` and a phone number `[phone]`. + +What is stored and shown is unchanged: the dossier, its contact channels, the +evidence and the published profile still hold every address and number. No +other call changes. + +A phone number is told from the other numbers in a text. Digits are a phone +number when the text says so (a `+` country code, or "tel", "mobil", "fax" in +front of them), or when there are eight or more of them, written the way +phone numbers are, and they do not read as something else. Years, dates, +opening hours, amounts (a currency, a percent sign, thousands in threes), +a street number beside a postcode, and numbers the text calls a registration, +VAT or customs number ("Org.nr.", "MVA", "KvK", "Company No.", "HS") stay. A +number that could be either goes: a bare nine digits in threes is how Spanish, +Portuguese, Polish and Czech phone numbers are written, and also a Norwegian +organisation number with nothing beside it to say so. Not caught: a local +number of fewer than eight digits with no label and no country code, digits +glued to letters, and an address or number spelled out in words. diff --git a/pipelines/src/distribution/redact.test.ts b/pipelines/src/distribution/redact.test.ts new file mode 100644 index 000000000..8d8202036 --- /dev/null +++ b/pipelines/src/distribution/redact.test.ts @@ -0,0 +1,251 @@ +/** + * What leaves a text and what stays. Every address and number here is made + * up: reserved example domains, zeros, counting runs, and the phone ranges + * set aside for fiction. + */ +import { describe, expect, it } from "vitest"; + +import { EMAIL_PLACEHOLDER, PHONE_PLACEHOLDER, withoutContactDetails } from "./redact"; + +/** The text with its one contact detail gone and nothing else touched. */ +function redacted(before: string, detail: string, after: string, placeholder: string): void { + expect(withoutContactDetails(`${before}${detail}${after}`)).toBe( + `${before}${placeholder}${after}` + ); +} + +describe("withoutContactDetails: email addresses", () => { + it.each([ + "someone@example.com", + "some.one+offers@mail.example.co.uk", + "SOMEONE@EXAMPLE.COM", + "post@bakeri.example", + "mailto:someone@example.com", + "someone [at] example [dot] com", + "someone (at) example.com", + "someone(a)example.com", + ])("removes %s", email => { + redacted("Example Bakery publishes a named mailbox: ", email, ".", EMAIL_PLACEHOLDER); + redacted("Write to ", email, " to order", EMAIL_PLACEHOLDER); + }); + + it("removes every address in a text", () => { + expect(withoutContactDetails("Sales: sales@example.com, press: press@example.org.")).toBe( + "Sales: [email], press: [email]." + ); + }); + + it.each([ + "Find us @ Eksempelgata 12", + "Follow @examplebakery for news", + "Option (a) is the bakery, option (b) the café", + ])("leaves %s alone", text => { + expect(withoutContactDetails(text)).toBe(text); + }); +}); + +describe("withoutContactDetails: phone numbers", () => { + it.each([ + // With a country code. + "+47 000 00 000", + "+4700000000", + "(+47) 00 00 00 00", + "0047 00 00 00 00", + "+44 20 7946 0000", + "+44 (0)20 7946 0000", + "+1 (555) 010-0100", + "+31 6 00000000", + "+49 30 0000000", + "+49 30 - 0000000", + "+49 (0) 30 000000-0", + "+34 000 000 000", + // As written inside a country. + "000 00 000", + "12 34 56 78", + "12345678", + "12.34.56.78", + "(555) 010-0100", + "555-010-0100", + "555.010.0100", + "020 7946 0000", + "07700 900000", + "030 0000000", + "030/0000000", + "030 / 0000000", + "030 - 00 00 00 0", + "06-00000000", + "01 00 00 00 00", + "0400.00.00.00", + "0400.000000", + "333/1234567", + "123 456 789", + "1234 5678", + "12345 67890", + "12-34-56-78", + "(12) 34 56 78", + ])("removes %s", phone => { + redacted("Call ", phone, " to order.", PHONE_PLACEHOLDER); + redacted("Example Bakery, ", phone, "", PHONE_PLACEHOLDER); + }); + + it.each([ + ["Tlf 00000", "Tlf [phone]"], + ["Tel.: 555 0100", "Tel.: [phone]"], + ["Telefon: 123 456", "Telefon: [phone]"], + ["Phone number: 555-0100", "Phone number: [phone]"], + ["Mobil 123 45 678", "Mobil [phone]"], + ["Fax: 030 000000", "Fax: [phone]"], + ])("removes a short number the text calls a phone number: %s", (text, expected) => { + expect(withoutContactDetails(text)).toBe(expected); + }); + + it("removes each of two numbers and keeps what is beside them", () => { + expect( + withoutContactDetails( + "Tlf: 12 34 56 78 / 87 65 43 21. Open 08.00-16.00 since 01.02.2024, call 000 00 000." + ) + ).toBe("Tlf: [phone] / [phone]. Open 08.00-16.00 since 01.02.2024, call [phone]."); + }); + + it("leaves the brackets around a number balanced", () => { + expect(withoutContactDetails("Reception (12 34 56 78) is open.")).toBe( + "Reception ([phone]) is open." + ); + expect(withoutContactDetails("Call +47 000 00 000 (9-16).")).toBe("Call [phone] (9-16)."); + }); + + it("finds a number beside a date, a postcode or an organisation number", () => { + expect(withoutContactDetails("Updated 27.11.2024 12 34 56 78")).toBe( + "Updated 27.11.2024 [phone]" + ); + expect(withoutContactDetails("Eksempelgata 12, 0155 Oslo 12 34 56 78")).toBe( + "Eksempelgata 12, 0155 Oslo [phone]" + ); + expect(withoutContactDetails("Org.nr. 987 654 321, tlf 12 34 56 78")).toBe( + "Org.nr. 987 654 321, tlf [phone]" + ); + }); + + it("removes both of two numbers joined by a comma", () => { + expect(withoutContactDetails("12 34 56 78,87 65 43 21")).toBe("[phone],[phone]"); + }); + + it("takes a number with a country code for a phone number whatever it is called", () => { + expect(withoutContactDetails("Company number: +44 20 7946 0000")).toBe( + "Company number: [phone]" + ); + }); + + it("does not take a word that only starts like a label for one", () => { + expect(withoutContactDetails("Registrer deg og ring nr 12 34 56 78")).toBe( + "Registrer deg og ring nr [phone]" + ); + }); + + it("does not take a company's name for a label", () => { + // "HS" before a number is a customs code; "HS AS" is a company. + expect(withoutContactDetails("Example HS AS 12 34 56 78")).toBe("Example HS AS [phone]"); + }); +}); + +describe("withoutContactDetails: numbers that are not phone numbers", () => { + it.each([ + // Years. + "Founded in 1987, family-run since 2004.", + "In business 1998-2024.", + "In business 1998–2024.", + "Won the award in the 2019/2020 season.", + "Prize winner 2021 2022 and 2023.", + // Prices and amounts. + "Turnover of kr 12 500 000 last year.", + "Turnover of 12 500 000 kr last year.", + "Turnover of NOK 125 430 210.", + "Turnover of 125 430 210 kroner.", + "Turnover of € 12.500.000 last year.", + "Turnover of 12.500.000,00 last year.", + "Turnover of 125 430 210,50 last year.", + "Turnover of $1,250,000 last year.", + "Turnover of 125 000 000 last year.", + "Orders from 1 250 000,- and up.", + "Sells 10 000-12 000 loaves a week.", + "Roasts 12 500 000 cups' worth of beans a year.", + "Turnover 2023 12 500 000", + "Founded 2015 - 120 000 customers since.", + // Postcodes. + "Eksempelgata 12, 0155 Oslo", + "Eksempelgata 123 0155 Oslo", + "Voorbeeldstraat 123, 1015 CJ Amsterdam", + "Beispielstraße 123 10115 Berlin", + "100 Example Street, Baltimore, MD 21201", + "100 Example Street, Baltimore, MD 21201-1234", + "1 Example Road, London SW1A 1AA", + // Organisation and registration numbers. + "Org.nr. 987 654 321", + "Org.nr: 987654321 MVA", + "Org. nr.: NO 987 654 321 MVA", + "NO 987 654 321 MVA", + "Organisasjonsnummer 987 654 321", + "Organisation number: 987654321", + "Vårt org.nr. er 987 654 321", + "Our company number is 01234567", + "VAT: NO 987 654 321", + "VAT Reg No. 123 4567 89", + "CHE-123.456.789 MWST", + "KvK 12345678", + "KvK-nummer: 12345678", + "CVR-nr. 12 34 56 78", + "VAT NL123456789B01", + "Company No. 01234567", + "Registered in England and Wales No. 01234567", + "SIRET 123 456 789 00012", + "HS code 0901.21.00", + // Percentages. + "45% of sales are wholesale.", + "Grew 12,5 % last year, 100 % organic.", + // Dates and opening hours. + "Opened on 27.11.2024.", + "Opened on 2024-11-27.", + "Opened on 11/27/2024.", + "Closed 01.01.2024-31.12.2024 for rebuilding.", + "Open 08.00-16.00.", + "Open Mon-Fri 0800-1600.", + // Other everyday numbers. + "Certified to ISO 9001:2015.", + "A team of 12 in 1 500 m² of bakery, open 24/7.", + "Found at 59.913868, 10.752245.", + ])("leaves %s alone", text => { + expect(withoutContactDetails(text)).toBe(text); + }); + + it("removes a nine-digit number in threes when nothing says what it is", () => { + // Spanish, Portuguese, Polish and Czech phone numbers and Norwegian + // organisation numbers are written alike; unlabelled, it goes. + expect(withoutContactDetails("Example Bakery, 987 654 321.")).toBe( + "Example Bakery, [phone]." + ); + expect(withoutContactDetails("Tel. 987 654 321")).toBe("Tel. [phone]"); + }); +}); + +describe("withoutContactDetails: whole sentences", () => { + it("takes the contact details out of a site's own sentence and keeps the rest", () => { + expect( + withoutContactDetails( + "Kontakt oss på post@bakeri.example eller ring 12 34 56 78 for bestilling. " + + "Example Bakeri AS, org.nr. 987 654 321, Eksempelgata 12, 0155 Oslo, har bakt brød siden 1987." + ) + ).toBe( + "Kontakt oss på [email] eller ring [phone] for bestilling. " + + "Example Bakeri AS, org.nr. 987 654 321, Eksempelgata 12, 0155 Oslo, har bakt brød siden 1987." + ); + }); + + it("changes nothing in a text with no contact details, and nothing the second time", () => { + const plain = "Wholesale bakery supplying cafés and hotels in Oslo since 1987."; + expect(withoutContactDetails(plain)).toBe(plain); + expect(withoutContactDetails("")).toBe(""); + const once = withoutContactDetails("Call +47 000 00 000 or write to someone@example.com."); + expect(once).toBe("Call [phone] or write to [email]."); + expect(withoutContactDetails(once)).toBe(once); + }); +}); diff --git a/pipelines/src/distribution/redact.ts b/pipelines/src/distribution/redact.ts new file mode 100644 index 000000000..f3786dd1c --- /dev/null +++ b/pipelines/src/distribution/redact.ts @@ -0,0 +1,185 @@ +/** + * Text without the contact details in it: email addresses and phone numbers + * give way to a placeholder, and everything else stays as written. For text + * that goes to a model provider when the answer does not turn on how to reach + * anyone. What is stored and shown never passes through here. + * + * An email address is plain to see. A phone number is not, because years, + * prices, postcodes, dates and registration numbers are digits too. Digits + * count as a phone number when the text says so (a "+" country code, or + * "tel", "mobil", "fax" in front of them), or when there are eight or more of + * them, written the way phone numbers are, and they do not read as something + * else: a date, opening hours, a run of years, an amount, a street number + * beside a postcode, or a number the text calls a registration, VAT or + * customs number. A number that could be either is taken for a phone number: + * an unlabelled reference number is little loss to a reader, and a phone + * number is what this is here to keep back. + * + * What it does not catch: a local number of fewer than eight digits with no + * label and no country code, digits glued to letters ("tlf12345678"), and an + * address or a number spelled out in words ("someone at example dot com"). + */ + +export const EMAIL_PLACEHOLDER = "[email]"; +export const PHONE_PLACEHOLDER = "[phone]"; + +/** A space as it is typed inside a number: plain, non-breaking or thin. */ +const SPACE = String.raw`[    ]`; + +// "someone [at] example [dot] com", "someone(a)example.com": addresses written +// so that a harvester misses them are addresses all the same. +const AT = String.raw`(?:@|\s?[\[({]\s?at\s?[\])}]\s?|[\[({][a@][\])}])`; +const DOT = String.raw`(?:\.|\s?[\[({]\s?(?:dot|punktum)\s?[\])}]\s?)`; +const EMAIL = new RegExp( + String.raw`(? g === "000"); + // 10 000-12 000: a range of amounts. + const sides = run.split("-"); + if (sides.length === 2 && sides.every(side => IN_THREES.test(side))) return true; + // 2023 12 500 000: a year and an amount. + if ( + run.startsWith(first) && + A_YEAR.test(first) && + ONE_SPACE.test(run.charAt(first.length)) && + IN_THREES.test(run.slice(first.length + 1)) + ) + return true; + if (groups.length !== 2) return false; + const join = run.slice(run.search(/\d/) + first.length, run.length - second.length); + // 59.913868 and 0.12345678: a decimal. + if (join === "." && (first === "0" || !first.startsWith("0"))) return true; + // 030 1234567: an area code and a number. + if (first.startsWith("0")) return false; + // 1169/2011: a reference or a ratio; 333/1234567 is a phone number. + if (join === "/") return second.length <= 4; + // 123 10115: a street number and a postcode. + return ONE_SPACE.test(join) && first.length <= 4 && second.length === 5; +} + +function isPhoneNumber(run: string, before: string, after: string): boolean { + const digits = run.replace(/\D/g, "").length; + if (SAYS_PHONE.test(before)) return digits >= 5; + if (digits < 8) return false; + if (MONEY_BEFORE.test(before) || NOT_A_PHONE_AFTER.test(after)) return false; + if (/^\(?\+/.test(run)) return true; + return !SAYS_REGISTER.test(before) && !readsAsAnotherNumber(run); +} + +/** The text with every email address and phone number replaced by a placeholder. */ +export function withoutContactDetails(text: string): string { + const held: string[] = []; + const searched = text + .replaceAll(HELD, "") + .replace(EMAIL, EMAIL_PLACEHOLDER) + .replace(NEVER_A_PHONE, match => { + held.push(match); + return HELD; + }); + return searched + .replace(DIGIT_RUN, (run: string, at: number) => + isPhoneNumber( + run, + searched.slice(Math.max(0, at - BEFORE), at), + searched.slice(at + run.length, at + run.length + AFTER) + ) + ? PHONE_PLACEHOLDER + : run + ) + .replaceAll(HELD, () => held.shift() ?? ""); +} diff --git a/pipelines/src/distribution/run.contact-details.test.ts b/pipelines/src/distribution/run.contact-details.test.ts new file mode 100644 index 000000000..efe406a09 --- /dev/null +++ b/pipelines/src/distribution/run.contact-details.test.ts @@ -0,0 +1,303 @@ +/** + * enrichCandidate's fit check after research: what the judge is sent holds no + * email address or phone number, while the dossier and the claims that are + * stored still hold them. The database here is in memory and keeps the claims + * research records, so that the fit check reads them back as it does in a run. + */ +import { beforeEach, describe, expect, it, vi } from "vitest"; + +import type { + Dossier, + PartnerOrgRecord, + ProgramRecord, + RelationshipRecord, + RunRecord, +} from "./types"; + +const store = vi.hoisted(() => ({ + /** Claims as insertEvidence stored them. */ + evidence: [] as Array<{ id: number; claim: string; capturedAt: Date }>, + /** Every setResearchResult call. */ + researched: [] as Array<{ dossier: unknown }>, + rows: {} as Record<"program" | "run" | "relationship" | "org", unknown>, +})); + +vi.mock("@launchstack/tools/company-context", () => ({ + getCompanyIdentity: async () => ({ + data: { + name: "Seller BV", + industry: "Logistics software", + description: "", + categories: [], + }, + }), + buildCompanyKnowledgeContext: async () => "", + formatCompanyIdentity: () => "Company: Seller BV.", +})); + +vi.mock("./db", () => ({ + getProgram: async () => store.rows.program, + getRun: async () => store.rows.run, + getRelationship: async () => store.rows.relationship, + getOrg: async () => store.rows.org, + insertEvidence: async (row: { claim: string }) => { + const saved = { + ...row, + id: store.evidence.length + 1, + capturedAt: new Date("2026-11-01T00:00:00Z"), + }; + store.evidence.push(saved); + return saved; + }, + listEvidenceForOrg: async () => store.evidence, + setResearchResult: async (_id: string, _companyId: bigint, result: { dossier: unknown }) => { + store.researched.push(result); + return null; + }, + updateOrg: async () => undefined, + addEvent: async () => undefined, +})); + +import { enrichCandidate, type DistributionPorts } from "./run"; +import { companyText } from "./semantic"; + +// Made up: a reserved example domain and a number of zeros. +const EMAIL = "someone@example.com"; +const PHONE = "+47 000 00 000"; + +const program = { + id: "prog-1", + companyId: 1n, + createdByUserId: "u1", + name: "NL fulfilment", + offering: "Picking robots for fulfilment warehouses", + categories: ["fulfilment"], + hsCodes: [], + targetTerritories: [{ country: "NL" }], + partnerKinds: ["distributor"], + constraints: null, + knownPartnerDomains: [], + customerDomains: [], + status: "active", + createdAt: new Date("2026-10-01T00:00:00Z"), + updatedAt: null, +} satisfies ProgramRecord; + +const run = { + id: "run-1", + companyId: 1n, + programId: "prog-1", + userId: "u1", + status: "enriching", + options: { maxCandidates: 25, mode: "live" }, + plan: null, + summary: null, + candidateOrgIds: ["rel-1"], + creditsUsed: 0, + errorMessage: null, + createdAt: new Date("2026-10-01T00:00:00Z"), + startedAt: new Date("2026-10-01T00:00:00Z"), + completedAt: null, +} satisfies RunRecord; + +const org = { + id: "org-1", + companyId: 1n, + resolveKey: "d:example-fulfilment.example", + name: "Example Fulfilment", + domain: "example-fulfilment.example", + country: "NL", + region: null, + city: null, + lat: null, + lng: null, + roles: [], + categories: ["fulfilment"], + sizeBand: null, + description: `Fulfilment and warehousing for webshops. Call ${PHONE}.`, + kgEntityId: null, + firstSeenRunId: "run-1", + lastEnrichedAt: null, + createdAt: new Date("2026-10-01T00:00:00Z"), + updatedAt: null, +} satisfies PartnerOrgRecord; + +const relationship = { + id: "rel-1", + companyId: 1n, + programId: "prog-1", + orgId: "org-1", + kind: "distributor", + territory: { country: "NL" }, + stage: "lead", + fitScore: null, + fitRationale: null, + fitBreakdown: null, + riskFlags: [], + screening: null, + dossier: null, + ownerUserId: null, + nextAction: null, + nextActionAt: null, + lastActivityAt: null, + dossierDocumentId: null, + source: "discovery", + stageChangedAt: new Date("2026-10-01T00:00:00Z"), + createdAt: new Date("2026-10-01T00:00:00Z"), + updatedAt: null, +} satisfies RelationshipRecord; + +const ctx = { runId: "run-1", companyId: 1n, programId: "prog-1" }; +const seller = { + companyName: "Seller BV", + industry: "Logistics software", + identity: "Company: Seller BV.", + knowledgeContext: "", +}; + +type Research = NonNullable; +type Asked = Parameters>[0]; + +/** Research that found these claims and wrote this summary, with one risk when given. */ +function researchThatFound(found: { summary: string; claims: string[]; risk?: string }): Research { + return async ports => { + const ids: number[] = []; + for (const claim of found.claims) + ids.push( + await ports.recordEvidence({ + kind: "firmographic", + claim, + sourceUrl: "https://example-fulfilment.example/", + quote: claim, + confidence: 0.8, + }) + ); + const cited = [ids[0]!]; + const dossier: Dossier = { + summary: found.summary, + roles: ["distributor"], + brandsCarried: [], + territories: [{ territory: "Netherlands", evidenceIds: cited }], + retailCoverage: [], + certifications: [], + decisionMakers: [], + contactChannels: [ + { channel: "email", value: EMAIL, evidenceIds: cited }, + { channel: "phone", value: PHONE, evidenceIds: cited }, + ], + risks: found.risk ? [{ risk: found.risk, evidenceIds: cited }] : [], + sizeBand: "unknown", + openQuestions: [], + }; + return { + outcome: { status: "ok", dossier, repaired: false }, + evidence: [], + fetchedUrls: [], + turns: 1, + usage: { inputTokens: 0, outputTokens: 0, totalTokens: 0 }, + playbookHash: "test", + promptVersion: "test", + }; + }; +} + +/** Research one company and hand back everything the fit check was asked. */ +async function fitCheckAfter(research: Research): Promise { + const asked: Asked[] = []; + const result = await enrichCandidate( + ctx, + { + model: { respond: vi.fn() }, + fetchPage: vi.fn(), + searchWeb: null, + searchPlaces: null, + tradeData: null, + compliance: null, + publishDossier: null, + debitCredits: null, + writeRationale: null, + creditsPerCandidate: 0, + profile: research, + judgeFit: async input => { + asked.push(input); + return new Map( + input.candidates.map(c => [c.id, { fit: true, reason: "Fulfilment." }]) + ); + }, + }, + { relationshipId: relationship.id, profile: seller } + ); + expect(result.status).toBe("ok"); + return asked; +} + +beforeEach(() => { + store.rows = { program, run, relationship, org }; + store.evidence = []; + store.researched = []; +}); + +describe("enrichCandidate's fit check after research", () => { + it("is sent what research found without its email addresses and phone numbers, which stay in what is stored", async () => { + const asked = await fitCheckAfter( + researchThatFound({ + summary: `We store, pick and ship for webshops from Utrecht, call ${PHONE} or write to ${EMAIL} for a quote.`, + risk: `The only way in is one person's mobile, ${PHONE}.`, + claims: [ + `Example Fulfilment publishes a named mailbox: ${EMAIL}.`, + `Example Fulfilment describes itself: We store, pick and ship for webshops from Utrecht, call ${PHONE} for a quote.`, + ], + }) + ); + + // Everything the fit check was handed, not only the company's text. + expect(asked).toHaveLength(1); + const sent = JSON.stringify(asked[0]); + expect(sent).not.toContain(EMAIL); + expect(sent).not.toContain("@"); + expect(sent).not.toContain("000 00 000"); + expect(sent).not.toContain("+47"); + // What the company does is still there to judge, with a mark where a detail was. + const text = asked[0]!.candidates[0]!.text; + expect(text).toContain("Example Fulfilment. Fulfilment and warehousing for webshops."); + expect(text).toContain("call [phone] or write to [email] for a quote"); + expect(text).toContain("The only way in is one person's mobile, [phone]."); + expect(text).toContain("publishes a named mailbox: [email]."); + expect(text).toContain("We store, pick and ship for webshops from Utrecht"); + + // What is stored and shown is what research found, contact details and all. + expect(store.researched).toHaveLength(1); + const stored = store.researched[0]!.dossier as Dossier; + expect(stored.summary).toContain(EMAIL); + expect(stored.summary).toContain(PHONE); + expect(stored.risks[0]!.risk).toContain(PHONE); + expect(stored.contactChannels.map(c => c.value)).toEqual([EMAIL, PHONE]); + const claims = store.evidence.map(e => e.claim).join(" "); + expect(claims).toContain(EMAIL); + expect(claims).toContain(PHONE); + }); + + it("is not sent half an address where the text is cut to length", async () => { + const summary = "A fulfilment company in Utrecht with a mailbox per team."; + const claims = Array.from( + { length: 20 }, + (_, team) => `Team ${team + 1} is reached at ${`${EMAIL} `.repeat(9).trim()}.` + ); + // As found, the text is cut part-way through an address. + const found = companyText({ + name: org.name, + description: org.description, + extra: [summary, ...claims], + }); + expect(found).toHaveLength(2_000); + expect(found).toMatch(/@[a-z.]*$/); + expect(found.endsWith(EMAIL)).toBe(false); + + const asked = await fitCheckAfter(researchThatFound({ summary, claims })); + + const text = asked[0]!.candidates[0]!.text; + expect(text).toContain("Team 1 is reached at [email] [email]"); + expect(text).not.toContain("@"); + expect(text).not.toContain("someone"); + }); +}); diff --git a/pipelines/src/distribution/run.ts b/pipelines/src/distribution/run.ts index 7ccf46441..eb2bd1a11 100644 --- a/pipelines/src/distribution/run.ts +++ b/pipelines/src/distribution/run.ts @@ -40,6 +40,7 @@ import { type SearchCompaniesPort, } from "./gather"; import { planDiscovery, type PlanInput, type SellerProfile } from "./plan"; +import { withoutContactDetails } from "./redact"; import { makeDossierCreationKey, makeDossierFilename, renderDossierMarkdown } from "./render"; import { bestTerritoryFit, placeLabel } from "./locate"; import { buildRationaleInput, computeFit, deriveRiskFlags, templateRationale } from "./score"; @@ -704,14 +705,17 @@ export async function enrichCandidate( { id: org.id, name: org.name, + // Without email addresses and phone numbers: they say + // nothing about fit, and on a small company's site + // they are often one person's. text: companyText({ - name: org.name, - description: org.description, + name: withoutContactDetails(org.name), + description: withoutContactDetails(org.description ?? ""), extra: [ dossier?.summary ?? "", ...(dossier?.risks.map(r => r.risk) ?? []), ...evidence.slice(0, 20).map(e => e.claim), - ], + ].map(withoutContactDetails), }), }, ],