Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions api/store.api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,15 @@ PeopleStore · interface · similar(name: string, options?: {
PeopleStore · interface · limit?: number;
PeopleStore · interface · }): Promise<SimilarPerson[]>;
PeopleStore · interface · ties(people: readonly string[]): Promise<Record<string, ShownBecause[]>>;
PeopleStore · interface · moveToBot(subject: string | IdentityRef, by: Decider, options?: {
PeopleStore · interface · bot?: string;
PeopleStore · interface · name?: string;
PeopleStore · interface · reason?: string;
PeopleStore · interface · }): Promise<SenderBot>;
PeopleStore · interface · moveToPerson(subject: string | IdentityRef, by: Decider, options?: {
PeopleStore · interface · person?: string;
PeopleStore · interface · reason?: string;
PeopleStore · interface · }): Promise<PersonRecord>;
PeopleStore · interface · }
PersonFacts · interface · export interface PersonFacts {
PersonFacts · interface · id: Id;
Expand Down
11 changes: 8 additions & 3 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -772,15 +772,20 @@
"noExcessiveLinesPerFile": {
"level": "error",
"options": {
"maxLines": 1890
"maxLines": 1893
}
}
}
}
}
},
{
"includes": ["src/crm/cli/index.ts", "src/store/sqlite/emails.ts", "src/store/sqlite/notes.ts"],
"includes": [
"src/crm/cli/index.ts",
"src/errors/reasons.ts",
"src/store/sqlite/emails.ts",
"src/store/sqlite/notes.ts"
],
"linter": {
"rules": {
"style": {
Expand Down Expand Up @@ -817,7 +822,7 @@
"noExcessiveLinesPerFile": {
"level": "error",
"options": {
"maxLines": 3255
"maxLines": 3260
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions changes/feat-bots-entity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
### Added

- **Sender bots, apart from people (store version 74).** A program that writes to the owner becomes a `sender_bots`
row. That covers a no-reply or alert address, a messenger bot, and a service's signed automatic mail. A bot is never
proposed as the same person and never offered by `people.similar`. It has no ties, and `tasks.assign` refuses it
with `sender-bot.assignee`. The owner's `store.people.moveToBot` and `moveToPerson` move a person, a bot or one
identity for its whole history. The owner's choice wins over the rules, and every move is logged in
`sender_bot_moves`. See [ARCHITECTURE.md, "Sender bots"](../docs/dev/ARCHITECTURE.md) and
[schema.md](../docs/storage/schema.md#sender_bots).
- **A page of people reads its List-Ids through an index** (`emails_by_list_id`). It no longer reads the List-Id of
every stored email.

### Changed — experimental

- **`people.list` rows have `bot`**: `sender-bot:<id>` for a sender bot, else `null`. A bot is still listed as
`automated` under its `person:<uid>` ref, so `people list kind:automated` and `people show` keep working. A bot's
`ties` are empty.
- **`KindSignal` gains `owner-choice`**: the signal of a bot the owner made when nothing else marks it.
- **`KIND_RULES` goes to 7.** The first list after the upgrade works out every kind again and moves the programs it
finds.
18 changes: 17 additions & 1 deletion docs/dev/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,23 @@ proposes them instead. A no-reply address (`isNoReplyAddress`) is no one's: it n
more than `SMALL_GROUP_MEMBERS` recipients; else `direct`. The owner missing from a To or Cc that names others says
nothing, since an alias the store does not know looks the same. The reach most of their mail had wins, the wider on a
tie; mail the owner wrote them or a private chat both wrote in makes it `direct`, and with no mail a one-to-one chat
or a small group does. `null` when nothing says. The page reads every stored email's List-Id once for this.
or a small group does. `null` when nothing says. The page reads the List-Ids of its people's mail, and the senders of
those lists through the index `emails_by_list_id` (version 74).
- **Sender bots** (`sender-bots.ts`, version 74): a program that writes to the owner is a `sender_bots` row, not a
person. A bot keeps the person row it was sorted from: its identities stay linked there, so ingest, merges, purges and
`people show person:<uid>` work as before, and `people.list` lists it as `automated` under that ref with
`bot: "sender-bot:<id>"` and no ties. Kept kinds move a person to a bot by rule when their kind is `automated` by a
program's signal (`PROGRAM_SIGNALS`: the platform's bot flag, a no-reply or notification address, a signed
`Auto-Submitted`, an empty Return-Path, `bulk_never_replied`), the owner wrote them nothing (no mail tie, no private
chat both wrote in; the platform's flag holds against both), no `ALWAYS_SHOWN` reason holds, and every identity of
theirs is the program's, or they have one. A name or a bulk mailbox alone marks a person `automated` and moves
nothing: a newsletter a human writes stays a person. A rule's bot goes back to a person when those rules stop holding.
The owner's `moveToBot` and `moveToPerson` move a person, a bot or one identity (one of several gets a person row of
its own first) for its whole history, and win over the rules and every `KIND_RULES` bump: a bot the owner made has
`author = 'owner'`, and an identity whose latest move is the owner's to a person is never moved by a rule. Every move
is a `sender_bot_moves` row. A bot is never joined to anyone by the matcher (`identity.not-a-person`), never assigned a
task (`sender-bot.assignee`), never offered by `people.similar` and has no ties in `people.ties`. Neither table has a
foreign key, so an older build erasing a person or purging an account still can; triggers drop their rows.
`people.similar` serves a form that adds a person: names starting like the typed words, the same `variantKey` first;
a `name:` search looks for the typed text in both scripts (`spellings`). Each row's `usernameSource` names the
messenger its `@username` belongs to.
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/COORDINATION.md

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion docs/reasons.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ headings.
| `identity.not-shared` | `validation_error` | only a match on a shared mailbox can say the mailbox is a company's | |
| `identity.nothing-left` | `validation_error` | a split leaves at least one identity with the person | |
| `identity.owner` | `validation_error` | one side is the owner's person, and only the owner joins anyone to themselves | |
| `identity.owner-only` | `permission_error` | only the owner undoes a merge, splits a person, confirms or undoes a link, or links an identity to themselves | |
| `identity.owner-only` | `permission_error` | only the owner undoes or confirms a merge, a split or a link, links an identity to themselves, or moves a sender | |
| `identity.rejected` | `conflict` | the owner rejected linking these people on this evidence; only a new signal or identity proposes them again | |
| `identity.same` | `validation_error` | the two identities are one person already | |
| `identity.separated` | `conflict` | the owner separated this identity from that person; only the owner links it again | |
Expand Down Expand Up @@ -515,6 +515,10 @@ headings.
| `selection.changed` | `validation_error` | the stored selection changed meanwhile | |
| `selection.invalid` | `validation_error` | the selection is not valid | |
| `selection.out-of-scope` | `permission_error` | the selection reaches outside what this profile may read | |
| `sender-bot.assignee` | `validation_error` | a sender bot is no one's assignee; move it to a person first | |
| `sender-bot.not-a-person` | `validation_error` | the person named is a sender bot; name a person | |
| `sender-bot.not-found` | `not_found` | no sender bot has that id; people list kind:automated lists them | |
| `sender-bot.owner` | `validation_error` | the owner's own person is never a bot | |
| `serve.outdated` | `configuration_error` | the store or the installed version is newer than this serve; it stopped so its unit starts the installed one | |
| `session.duplicate` | `conflict` | another profile here already signs in to this account as this user | |
| `session.missing` | `authentication_error` | this profile is not signed in: no saved sign-in or API token | |
Expand Down
37 changes: 35 additions & 2 deletions docs/storage/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Every table of the shared store (tg, max, memo, zm) as its migrations create it.
`drizzle/` must agree with it. `pnpm schema:check` fails when they do not, and `src/store/sqlite/schema.test.ts`
checks every table and column of a new store against this page.

145 tables, 28 full-text indexes.
147 tables, 28 full-text indexes.

## Conventions

Expand Down Expand Up @@ -333,6 +333,39 @@ An AI agent or a script that works here: it registers itself, owns projects and

*Checks:* `CHECK ("metadata" IS NULL OR json_valid("metadata"))`

### `sender_bots`

A program that writes to the owner: a no-reply or alert address, a messenger bot, a service's mail. Not a person, so it is never proposed as the same person, has no ties and is no task's assignee. Its identities are those of the person row it was sorted from, which `people list` shows as `automated`. Not the `bots` table, which holds agents that work here.

| Column | Type | Constraints | References | Meaning |
|---|---|---|---|---|
| `id` | integer | PK | | |
| `person_id` | integer | not null, unique | | the person row whose identities are this bot's; its `person:` uid stays the bot's handle in lists. No foreign key: an older build erasing the person does not know this table, and a trigger drops the bot with it |
| `name` | text | | | the owner's name for it; null shows its identities' name |
| `organization_id` | integer | | | the organization it sends for; no foreign key, a trigger clears it when the organization row goes |
| `author` | text | not null | | `rules` or `owner`: the owner's bot never goes back by a rule |
| `reason` | text | | | what sorted it: the kind signals, such as `no-reply`, or the owner's words |
| `created_at` | integer | not null | | when this row was saved here |
| `updated_at` | integer | not null | | when this row last changed here |

### `sender_bot_moves`

Every move of an identity between a person and a sender bot, by the rules or by the owner. An identity whose latest move is the owner's is never moved by a rule again. A trigger drops an identity's rows with it.

| Column | Type | Constraints | References | Meaning |
|---|---|---|---|---|
| `id` | integer | PK | | |
| `identity_id` | integer | not null | | no foreign key: an older build purging an account does not know this table |
| `from_person_id` | integer | | | the person it left, or null |
| `from_bot_id` | integer | | | the sender bot it left, or null |
| `to_person_id` | integer | | | the person it went to, or null |
| `to_bot_id` | integer | | | the sender bot it went to, or null |
| `author` | text | not null | | `rules` or `owner` |
| `reason` | text | | | the kind signals of a rule's move, or the owner's words |
| `created_at` | integer | not null | | when it moved |

*Keys and indexes:* `INDEX (identity_id)`

## Chats and messages

What messengers bring.
Expand Down Expand Up @@ -765,7 +798,7 @@ One email.
| `deleted_at` | integer | | | gone at the source; sync never hard-deletes |
| `mail_rule_id` | integer | | | the `mail_rules` row that decided how this email is stored; no constraint, removing the rule clears it |

*Keys and indexes:* `UNIQUE (account_id, external_id)`, `INDEX (account_id, sent_at DESC)`, `INDEX (mail_rule_id) WHERE mail_rule_id IS NOT NULL`, `INDEX (email_thread_id)`, `INDEX (from_identity_id)`
*Keys and indexes:* `UNIQUE (account_id, external_id)`, `INDEX (account_id, sent_at DESC)`, `INDEX (mail_rule_id) WHERE mail_rule_id IS NOT NULL`, `INDEX (coalesce(json_extract(headers, '$."list-id"'), json_extract(metadata, '$.listId')))`, `INDEX (email_thread_id)`, `INDEX (from_identity_id)`

*Checks:* `CHECK ("references" IS NULL OR json_valid("references"))`, `CHECK ("headers" IS NULL OR json_valid("headers"))`, `CHECK ("metadata" IS NULL OR json_valid("metadata"))`

Expand Down
25 changes: 25 additions & 0 deletions drizzle/20261125025700_version-74-sender-bots/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TABLE `sender_bot_moves` (
`id` integer PRIMARY KEY AUTOINCREMENT,
`identity_id` integer NOT NULL,
`from_person_id` integer,
`from_bot_id` integer,
`to_person_id` integer,
`to_bot_id` integer,
`author` text NOT NULL,
`reason` text,
`created_at` integer NOT NULL
);
--> statement-breakpoint
CREATE TABLE `sender_bots` (
`id` integer PRIMARY KEY AUTOINCREMENT,
`person_id` integer NOT NULL UNIQUE,
`name` text,
`organization_id` integer,
`author` text NOT NULL,
`reason` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL
);
--> statement-breakpoint
CREATE INDEX `emails_by_list_id` ON `emails` (coalesce(json_extract(headers, '$."list-id"'), json_extract(metadata, '$.listId')));--> statement-breakpoint
CREATE INDEX `sender_bot_moves_by_identity_id` ON `sender_bot_moves` (`identity_id`);
Loading
Loading