Repository navigation
feat(people): organizations from mail domains - #3347
Merged
Merged
Conversation
Plan step 5 of the contact-kinds plan. When kinds are kept, a sender bot or a shared mailbox at a company domain joins the organization of its registrable domain: the one already holding an address there, else a new company named by the sender (a company name or the domain's own word) or by the domain. Its addresses go to organization_identities (method domain, author rules) and a bot's sender_bots.organization_id is set. A human writing from that domain gets a member-of link, never a merge or a proposal; humans alone make no organization. Free mail, throwaway mail (disposable-email-domains-js, already a dependency) and a hand table of sending platforms are never company domains. The owner's word holds: a removed member-of leaves a rejected relationship proposal the rule checks, erasing an organization leaves a rejected organization-domain proposal per domain, and moveToPerson drops the rule's holds. No migration; KIND_RULES goes to 8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 25, 2026
leemour
added a commit
that referenced
this pull request
Nov 25, 2026
## Task Follow-up to #3347: its PR body noted that `isDisposableEmailDomain` (`disposable-email-domains-js`) builds its whole list on every call, and that `src/mail/score.ts` still called it once per sender. ## Why The library's `isDisposableEmailDomain` turns its array of about 9,000 domains into a new `Set` on each call. `scoreGroup` calls it for every sender group, so scoring a large mailbox spent most of its time rebuilding the same set. ## What - `src/mail/score.ts`: new `isDisposableDomain(domain)`, which builds the set once (`disposableEmailBlocklistSet`) on first use. `scoreGroup` uses it. - `src/store/sqlite/domain-organizations.ts`: its private cache from #3347 is gone; `companyDomainOf` imports `isDisposableDomain` from the same module it already takes `FREE_MAIL` and `registrableOf` from. - Changelog fragment under "Fixed". **Decision (owner asleep):** the shared helper lives in `mail/score.ts`, next to `FREE_MAIL`, rather than in a new module. Both callers already import from there. The input is not lower-cased or trimmed, unlike the library function: both callers pass `registrableOf` output, which is lower case already. ## Testing **Measured**, synthetic case: 20,000 senders, 3 emails each (every tenth at `mailinator.com`), `scoreGroup` over all of them, 5 runs in one process, vitest `--maxWorkers=1`, Node 24.19, 24 cores, load average about 5. The timing file was a throwaway test, not committed. | | Runs (ms) | Median | |---|---|---| | Before (`origin/main`) | 8026, 7116, 6948, 6987, 7255 | 7.0 s | | After | 240, 209, 218, 208, 207 | 0.21 s | About 0.35 ms per sender before, 0.01 ms after (that is the whole score, not only the check). - New test in `src/mail/score.test.ts`: `isDisposableDomain` is true for `mailinator.com` and `guerrillamail.com`, false for `gmail.com` and a company domain. The existing `disposable_domain` signal test still passes. - `src/mail/score.test.ts`, `src/store/domain-organizations.test.ts`: 22 passed. - `pnpm typecheck`, `pnpm lint` (no new warnings), `pnpm docs:check`, `pnpm schema:check`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
leemour
added a commit
that referenced
this pull request
Nov 25, 2026
…3350) ## Task Contact-kinds plan, "Domain lists" (plan step 5, second half): an organization gets what it does (bank, airline, shop, news, government, …) from a domain list built into the package. Open question 4 is answered with the default: the list is built into the package at release, with no network at run time. Part of #3314. ## Why After #3347, a bank's no-reply bots and mailboxes are one organization, but nothing says it is a bank. Desktop's Bots and Organizations tabs need that for their filter. A lookup per sender (a category API, DNS) would tell a third party who writes to the owner, so the table ships with the package. ## What - **Data:** `scripts/organization-sectors.ts` queries the Wikidata SPARQL endpoint (https://query.wikidata.org/sparql), one class after another, and writes `src/domain/organization-sectors.generated.ts`. Header: CC0 1.0 and the export date (2026-11-25). The file is **358 KB, 25,639 domains**: | sector | domains | Wikidata items | classes (with subclasses unless noted) | |---|---|---|---| | airline | 1,695 | 1,867 | Q46970 | | bank | 3,571 | 3,796 | Q22687 | | financial | 3,488 | 7,826 | insurance Q2143354, payment provider Q1956140, crypto exchange Q25401607, stock exchange Q11691, financial institution Q650241 | | telecom | 718 | 752 | Q2401749, Q1941618, ISP Q11371 | | social | 651 | 677 | Q3220391 | | shop | 3,754 | 3,704 | Q4382945, Q3390477, Q507619, Q18043413, Q216107; 2+ sitelinks | | delivery | 120 | 126 | postal service Q1529128 | | news | 7,592 | 9,651 | Q1193236, Q11032, Q192283, Q17232649, Q1153191, Q15265344, Q2001305; 3+ sitelinks | | government | 4,050 | 6,039 | ministry Q192350, revenue service Q573607, government agency Q327333 (direct instances only); 2+ sitelinks | - **Query rules:** the official website (P856) at its best rank, no end date (P582), of an item not dissolved (P576). The registrable domain comes from tldts, the same way `registrableOf` reads mail. The User-Agent is `WireCat-build/1.0 (https://github.com/WireCatLabs/cli-core)`; the query sends class ids only. Queries run one at a time with 1 s between them, inside the limits [the WDQS manual](https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual#Query_limits) describes (60 s per query, 5 parallel). A 429 waits for `Retry-After`. A 502/503/504 is tried again, and a timeout splits the query into the class's direct subclasses. A full run takes about 10 minutes. - **Apply:** at the end of `groupByDomain`, every organization holding a company domain gets `metadata.sector` (the JSON column already exists, so there is no migration and no #3157 reservation). It is written only when the value changes. Only domains that pass `companyDomainOf` are looked up, so free mail, throwaway mail and sending platforms never give a sector. None of them is in today's table: an earlier export without the host rule had `mail.ru` as social. `KIND_RULES` goes to 9, so existing stores get the pass on their next list. - **Exposed:** `Organization.sector: Sector | null` on every organization row the store returns. The `organization` entity (`src/entities/knowledge-lists.ts`, also used by `organization_context`) has `sector`, nullable. `Organization` moved next to its mapper in `organizations.ts`; `knowledge.ts` re-exports it because that file is at the 1,000-line lint limit. - **Docs:** ARCHITECTURE (organizations from mail domains), the schema spec and `schema.md` (the `organizations` doc names `metadata.sector`), THIRD_PARTY_NOTICES (Wikidata, CC0), a changelog fragment. **Left open:** - A sector is never cleared. It stays when a later export drops the domain or the organization stops holding it. - A pass with no company mail skips the sector step: `groupByDomain` returns early. - The owner cannot set or clear a sector, and memo and Desktop do not show or filter by it yet. - DKIM-domain matching (plan) is not built. **Decisions I made (owner asleep):** - **Named `sector`, not `category`.** `Category` already exists (`src/domain/categories.ts`): client / supplier / partner / employer, derived from relationships, and it is `organizations({ category })`'s filter. One word for two meanings would confuse every caller. Renaming is cheap now if the owner prefers `category`. - **Best rank, not preferred only.** Preferred-only statements keep 227 of 3,796 banks. Best rank is the preferred statement where one exists, else the normal one. - **Only home pages.** A URL with a path other than `/` or a language folder is dropped, and so is a host other than the domain itself or `www`. Without this rule, banks' Facebook pages made `facebook.com` a bank, YouTube TV made `youtube.com` news, and blogs made `wordpress.com` news. - **A notability floor** (Wikipedia sitelinks) for shop, news and government. Without it the file was 1.6 MB and about 90,000 domains, mostly local newspapers. Government agency's subclass tree also pulls in about 50,000 towns, so only its direct instances count. - **Precedence** is the table order, most specific first. A domain claimed by 3 or more sectors is dropped (a conglomerate or a host). - **UT1 is not included** (CC BY-SA). That is left to the owner. ## Testing All runs used `--maxWorkers=1`. - New `src/domain/organization-sectors.test.ts`: every domain appears once, in lower case, and is registrable. - New integration test in `src/store/domain-organizations.test.ts`: - a bot at `mail.hsbc.com` → organization `HSBC` with `sector: "bank"`; - a company outside the table → `null`; - an organization holding a `mail.ru` address (free mail) → `null`. This guards against a later export listing it; today's table does not; - a second full pass changes no `organizations` row. - Passed: `domain-organizations`, knowledge, organization-erase, owner-labels, mail-findings, people-list, sender-bots, people-kinds-stored, crm, records-matching, business-review, areas, `mail/score`. - Some store tests timed out at 15 s on one run. That happened on unchanged `main` too (crm.test.ts took 30 s on main against 1.4 s on this branch, one after the other), so it was machine load. They passed when run alone. - The 40 test files that read organizations (398 tests) and `entities.test.ts` passed; the entity samples have `sector`. - `pnpm typecheck`, `pnpm lint` (no new warnings), `pnpm docs:check`, `pnpm schema:check`. - Cost: loading the table takes 4 ms, and building the lookup map on first use takes 13 ms (from `dist`, Node 24). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
leemour
added a commit
that referenced
this pull request
Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Task
Plan step 5 of the contact-kinds plan (plan #3323, "Grouping under an organization"): organizations from mail domains, with the three exceptions. Part of #3314.
Why
After #3339 a program that writes to the owner is a sender bot, but nothing says whose bot it is. Ten no-reply and
info@addresses of one bank showed as ten unrelated senders. People at that bank had no link to it either.What
The rule (
src/store/sqlite/domain-organizations.ts, run fromkeep()inpeople-list.tsafter the rule moves and before the kinds are written):organizationbyrole-address), at a company domain joins the organization of its registrable domain (registrableOf/ tldtsgetDomain:mail.bank.ruandbank.ruare one).companyis made, named by the sender when the name is a company's (isCompanyName) or equals the domain's own word (Bankforbank.ru); otherwise it is named by the domain.organization_identitieswith methoddomain, authorrules, and the bot'ssender_bots.organization_idis set.member-oflink (authorrule,metadata.derived = "mail-domain", confirmed). They are never merged. A new organization also links the humans already stored at its domain.FREE_MAIL; throwaway mail fromdisposable-email-domains-js(CC0, already a dependency, so nothing was vendored); andSENDING_PLATFORMS, a hand table. A platform domain never groups anything.knowledge.removeRelation). The existing rejectedrelationshipproposal is checked, and the link is never added again.knowledge.eraseOrganization). This leaves a rejectedproposed_actionsrow of kindorganization-domainfor each company domain it held, and the rule never makes an organization for that domain again. The row is written only from the owner-facing erase, not from a CRM purge's clean-up.moveToPerson). The rule's holds on those identities go. A person the owner kept as a person holds nothing; they can still be a member.KIND_RULESgoes to 8, so the first list after the upgrade groups the senders already stored.Decisions I made (owner asleep):
sender_bots.organization_id,organization_identities.method/authorandlinks.authoralready exist, so I made no cli-core: merges into main and release runs — announce here first (continues #849) #3157 reservation.personal, the schema default. The other automatic creators usework, but these senders are mostly services the owner uses privately.member-ofrole is null. The rule cannot tell an employee from a contact.owner, authorrulefollows thetasks.tsanswered-byprecedent.LINK_ORIGINShas norule.Fromis matched. The plan's DKIM-domain matching and grouping byList-Idor display name inside a platform are not built. The bounce and DKIM entries in the table guard mail whoseFromcarries them.Sending platforms, checked against vendor pages on 2026-11-25:
amazonses.com(AWS),mandrillapp.com(Mailchimp),mtasv.net(Postmark),ghost.io(Ghost),mcsv.net,mcdlv.net,mailchimpapp.net,rsgsv.net(Mailchimp)sendgrid.net(Twilio; the page does not name the header),buttondown.email(Buttondown blog, not docs),mailgun.org(sandbox only)substack.com,sparkpostmail.com,brevosend.com,beehiiv.combuttondown.com,list-manage.com,postmarkapp.com,mailgun.net,convertkit-mail.com,sendinblue.com,mlsend.comPERF (found, not fixed here):
isDisposableEmailDomainbuilds its whole set on every call, about 0.5 ms each. The new module builds the set once.src/mail/score.tsstill calls the slow function per sender.Gaps left:
moveToPerson. No store method detaches one address. memo needs one before it can offer "not this company".categoryfrom domain lists (out of scope).Testing
All runs used
--maxWorkers=1.src/store/domain-organizations.test.ts(7 integration tests):info@atmail.bank.ru/bank.ru→ one organization namedBank, and the bot'sorganization_idis set;gmail.comandmailinator.com→ none;substack.complus one onghost.io→ no organization, no membership;member-of, whether the human came first or later, and no proposal;people-list.test.ts: the shared mailboxinfo@hotel.runow also has theorganizationsignal, because an organization holds it.pnpm typecheck,pnpm lint,schema:check,docs:check, andcommand-lint.Cost, on a synthetic store with 22,000 senders: 10,000 no-reply bots and 4,000 role mailboxes across 2,000 domains, 6,000 humans at those domains, and 2,000 at gmail. Load average was about 15.
All of it runs under the write lock, well under the other writers' 5 s wait. Before the disposable-set fix, the pass with nothing to do took 13 s.
🤖 Generated with Claude Code