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
99 changes: 99 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,105 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- **Inbox Agent works through a request step by step.** It now decides for
itself what to look up before it answers: it searches with exact filters
(sender, date, unread, starred, folder, label, category), counts mail, reads
whole conversations and attachments, sorts many emails against a question
you ask ("which of these are about business?"), and looks up your contacts
and how much mail a sender has sent you. Answers still link to the emails
they come from. Requests it used to turn down, such as categorizing or
archiving mail from the chat, now work. A very large clean-up can take more
than one request.
- **Inbox Agent can change your mail when you ask.** It can mark mail read or
unread, star or unstar it, archive it, move it to Trash or back, move it to a
folder, add or remove a label or category, snooze it until a time or wake it,
and report it as spam or not spam. Each change is a card under the answer
that lists the emails, and why each was picked when the agent sorted them.
With **Ask for approval** (every new conversation starts there), nothing
changes until you choose **Approve**, **Approve selected** or **Cancel**; a
card can be approved for 30 minutes after the answer arrives. Every applied
change has **Undo** on its card for 24 hours, and Undo leaves alone any email
that was changed again since. The agent can pick only emails it found for
that request, in the accounts you selected, so text inside an email cannot
point it at other mail. Approving a move to Trash asks you once more. A spam
report (which also sends that sender's future mail to Spam) and a label that
does not exist yet always wait for your approval. The agent never deletes
mail permanently and never sends mail.
- **Protected emails stay as they are unless you tick them.** When a change
would take mail out of sight (marking it read, archiving it, moving it to
Trash, another folder or Spam, or snoozing it), the card leaves protected
emails unticked and says why: security codes, bank and card records,
invoices and contracts, business reports, starred or important mail,
calendar invitations, encrypted mail, mail you filed in a category yourself
(other than Promotions, Social, Updates and Forums), mail from a VIP sender
(a favorite contact, or a sender you made a VIP), conversations you replied
to in the last 30 days, mail from colleagues at your own company's domain,
mail whose content has not been downloaded yet, and mail with attachments.
If the app cannot check an email, it treats it as protected. An email stays
protected for the rest of a request even after an earlier step of that
request unstarred it or took it out of its category, and in the
conversation's later requests too while the agent's own change can still be
undone. An email you star or mark important after a card was prepared is
left as it is when you approve the card. Including a protected email asks
you to confirm.
- **Inbox Agent can set up filters and change how a sender is treated.** Ask
it to create, change or delete a filter, or to block or unblock a sender,
make them a VIP or trust them. Each one is its own card and always waits for
your approval, even with Approve for me on. A new or changed filter offers to
act on the mail it matches now, and blocking a sender offers to move their
existing mail to Spam. Both boxes start unticked and show how many emails
they cover, and protected emails among them are not marked read, moved or
hidden. **Undo** reverses the setting and that mail, but keeps a filter or a
sender you changed yourself since. The agent acts only on a sender you named
or one whose mail it found, never on an address it read inside an email.
- **"Undo that."** Ask Inbox Agent to undo an earlier change in the same
conversation. With Ask for approval, and for filters and sender changes
always, it shows that change's card again under its answer with only its
**Undo** button, and nothing changes until you click it. With Approve for me,
it undoes a change it made on its own straight away, counted in the same
200-email limit. A change you approved on its card, a spam report, a new
label, or an undo that would take mail out of sight again (marking it read,
moving it out of the Inbox or back to Trash, Archive or Spam, snoozing it
again) still waits for your click.
- **Inbox Agent's cards keep working after a restart.** A card waiting for
your approval, or one you can still undo, keeps its buttons when the app
restarts, for as long as it can be approved (30 minutes) or undone
(24 hours). A change the agent made on its own is saved with its card the
moment it is made, so it keeps its Undo even if the app quits before the
agent finishes the request.
- **Changing a whole conversation leaves your own mail alone.** When the agent
changes every email in a conversation, it never touches your drafts, and a
move to a folder leaves your own sent replies in Sent.

### Changed
- **Inbox Agent asks again before changing mail in conversations where
Approve for me was on.** Approve for me now also archives, moves to Trash or
back, moves to folders, adds and removes labels and categories, snoozes and
wakes, and stars and unstars mail, up to 200 emails per request with Undo on
each change, where before it only marked mail read or unread. A bigger
change waits for your approval on its card. So those conversations start on
**Ask for approval** after this update. Turn Approve for me on again in a
conversation to allow the wider changes; the app shows exactly what it
covers before it turns on. Marking read, archiving, moving or snoozing
protected emails, spam reports, new labels, filters and sender changes
always ask, and it never sends mail or deletes it permanently. The mode
cannot be changed while the agent is working on a request: stop the request
first.

### Removed
- **The unread and uncategorized mail review cards.** This includes **Mark
recommended & continue**, which marked recommended mail read in automatic
batches, up to ten per run. Ask Inbox Agent instead, for example "review my
unread mail and mark the newsletters as read": it finds and sorts the mail
and prepares a change card (or, with Approve for me on, applies it), and
protected emails stay unread unless you tick them. Reviews saved by an
earlier version still show their text, but their buttons are gone.
- **The separate "mark as read" command.** A request such as "mark all from
this sender as read" no longer runs a phrase-matching command of its own. It
goes to the agent like any other request, which finds the emails it means
and prepares a card.

## [1.4.12] - 2026-11-24

### Fixed
Expand Down
22 changes: 22 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,22 @@ Established shared helpers (extend this list as you add more):
- `hostIsOrUnder(host, domain)` — `packages/core/src/utils/host-match.ts` (renderer:
`@sarvinbox/core/host-match`). Whether a host is a domain or a subdomain of it,
never a substring match.
- `setEmailLabel(storage, emailId, name, on)` — `apps/desktop/electron/services/email-labels.ts`.
The one way a label (a tag) goes on or off an email; answers `changed`,
`unchanged` or `missing`. Used by `emails:setLabel` and the Inbox Agent.
- `emailsMatchingRule(storage, rule)` / `emailsFromSender(storage, address)` —
`apps/desktop/electron/services/filter-matching.ts`. Which stored emails a
filter rule matches (the Filters page's count and "apply to existing"), and
a sender's mail by exact address. Use them instead of another scan.
- `revertUserSpamVerdict(deps, row)` — `apps/desktop/electron/services/spam-verdict-actions.ts`.
Undo of Report spam / Not spam: tag, folder, stored verdict and the sender's
lists back as they were; refuses while the moved message has no server UID.
- `changeProtection(action, email, body)` / `createConversationGuard({ storage, ownAddresses, nowMs })` —
`apps/desktop/electron/services/inbox-assistant-change-sets.ts`. Why mail must not be
hidden (marked read, archived, trashed, moved, reported) without the user ticking it:
the email's own flags and content, then its sender (VIP) and conversation (the user's
recent reply, a colleague). A failed lookup protects. Use both for any new path that
changes mail on the agent's behalf.
- `isAllowedArchiveEntry(path, entry)` —
`apps/desktop/electron/services/extension-archive-rules.mjs`. What may come out of
an extension archive (allowlisted paths, plain files and the expected folders,
Expand Down Expand Up @@ -400,6 +416,12 @@ Established shared helpers (extend this list as you add more):
An http(s) address that is an origin and nothing else (no userinfo, path, query
or fragment). The Sarv reputation rule and the scanner origin are built on it;
use it for any setting that must name a service origin.
- `stageChangeSet` / `applyChangeSet` / `undoChangeSet` —
`apps/desktop/electron/services/inbox-assistant-change-sets.ts`. The one way the
Inbox Agent changes mail: a frozen set of messages it was shown, applied on the
user's approval (or within the "Approve for me" cap), each row at most once,
protected rows only when ticked, Undo only for rows still as the set left them.
A new agent write tool stages through it; never call a mail action from a tool.
- `createAssistantHarness()` — `apps/desktop/test/helpers/assistant-harness.ts`.
The real Inbox Agent end to end for tests (real databases, history store and
provider call path; scripted network). Use it instead of hand-wiring
Expand Down
19 changes: 19 additions & 0 deletions apps/desktop/electron/app-identity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { app } from 'electron';

import { isDevBuild } from './utils/dev-mode';

/**
* The app's identity, set before ANY other main-process module loads.
*
* `app.name` decides the userData folder ("Sarv Inbox Dev" vs "Sarv Inbox"),
* the macOS menu name and the safeStorage keychain item. Electron fixes the
* userData path the first time anything reads it, so a module that touches
* the data folder, the core database or the keychain while it loads would,
* if it ran before this, tie a dev run to the INSTALLED app's data and key.
* That happened on 2026-11-19 (a service that read the core database in its
* constructor). main.ts imports this file first, so the name is in place
* before any other import's top level runs.
*/
export const isDev = isDevBuild();
export const APP_NAME = isDev ? 'Sarv Inbox Dev' : 'Sarv Inbox';
app.name = APP_NAME;
47 changes: 5 additions & 42 deletions apps/desktop/electron/ipc/filter-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,18 @@
* ingest in the core message-processor; these handlers just manage the records.
*/

import { collectFilterActions, computeFilterActionResult, emailMatchesRule, type FilterCondition, type FilterRule, type FilterRuleInput } from '@sarvinbox/core';
import { cleanBodyExpression } from '@sarvinbox/storage-node';
import { collectFilterActions, computeFilterActionResult, type EmailRecord, type FilterCondition, type FilterRule, type FilterRuleInput } from '@sarvinbox/core';
import { ipcMain } from 'electron';

import { emailsMatchingRule, scanEmailsForFilter } from '../services/filter-matching';
import { requireStorage, getSyncEngine } from '../shared';

// Cap the existing-mail scan so applying/counting a filter can't lock up on a
// huge mailbox. Newest-first, so the most relevant mail is always covered.
const APPLY_TO_EXISTING_SCAN_CAP = 5000;

/**
* Newest-first slice of stored emails with just the fields filter conditions
* read. Shared by the count-preview and apply paths.
*/
function scanEmailsForFilter(): any[] {
const storage = requireStorage();
const db = (storage as any).db;
if (!db?.prepare) return [];
return db
.prepare(`
SELECT id, folder_id AS folderId, uid, tags, subject,
from_address AS fromAddress, from_name AS fromName,
to_address AS toAddress, cc_address AS ccAddress,
-- Through email_bodies, never the inline column: migration 73 empties
-- it, and a filter rule matching on body text would silently stop
-- matching anything.
${cleanBodyExpression()} AS cleanBody
FROM emails
ORDER BY date DESC
LIMIT ${APPLY_TO_EXISTING_SCAN_CAP}
`)
.all() as any[];
}

/**
* Count how many existing emails an (unsaved) rule would match — used for the
* live "N matching emails" preview when the user ticks "apply to existing".
*/
function countRuleMatches(input: { matchType: 'all' | 'any'; conditions: FilterCondition[] }): number {
const rule: FilterRule = {
id: '', name: '', enabled: true, priority: 0,
matchType: input.matchType, conditions: input.conditions, actions: [],
stopProcessing: false, createdAt: 0, updatedAt: 0,
};
let count = 0;
for (const email of scanEmailsForFilter()) {
if (emailMatchesRule(email, rule)) count++;
}
return count;
return emailsMatchingRule(requireStorage(), input).length;
}

/**
Expand All @@ -66,13 +29,13 @@ async function applyRuleToExistingEmails(rule: FilterRule): Promise<number> {
const storage = requireStorage();
const syncEngine = getSyncEngine();
const folders = await storage.getFolders();
const rows = scanEmailsForFilter();
const rows = scanEmailsForFilter(storage);

const connected = syncEngine?.isConnected?.() ?? false;
let affected = 0;

for (const email of rows) {
const actions = collectFilterActions(email, [rule]);
const actions = collectFilterActions(email as EmailRecord, [rule]);
if (actions.length === 0) continue;

const { tags, folderId, changed } = computeFilterActionResult(email, actions, folders as any);
Expand Down
Loading
Loading