diff --git a/AGENTS.md b/AGENTS.md index 4edeca51..26cb9b92 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -94,6 +94,10 @@ agent's in-flight work. Say where the worktree is, and remove it once the work h `unauthorized`, `unconfigured`, …) instead of an empty one, retry sooner after a failure, and validate every command payload with zod. Commands that run a program use `execFile` with an argument list, never a shell, and only accept what a closed list or a strict schema allows. + An account provider never publishes the account's e-mail unless `privacy.showAccountEmail` is + on: build the snapshot with `withAccountEmail()` from `server/src/privacy.ts`, pass every + snapshot it returns — the error path's `{ ...last, error }` included — through + `gateAccountEmail()`, applied to the object that carries `email` when it is nested, and set `publishesAccountEmail: true` (see `docs/connections.md`). - **Config schema** changes go through `server/src/config/schema.ts` with a migration in the same commit and a test; the store never rewrites a file it could not migrate. - **Commits**: small, one concern each — a native fix noticed *while I was in there* is its own diff --git a/CHANGELOG.md b/CHANGELOG.md index bb252d14..7ed00bb3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,10 @@ Anything that changes what the dashboard, the admin or a widget can do gets a li - **Local Docker and AI models.** Registry widgets can show up to 200 local containers and observed Ollama or MLX models. Fremkit refuses remote Docker contexts, distinguishes a missing CLI from a stopped daemon, and keeps the container list when stats fail. - **The Uptime tile shows time since boot.** The reading comes from macOS and remains unavailable when the system cannot provide it. - **Borrow the Edge display.** Hide or show the dashboard from the helper menu without quitting it. Hidden state survives display rearrangements, and the mouse fence pauses while the Edge is borrowed. Touch and data collection continue; the dashboard reappears after a helper restart. +- **Account e-mail stays private.** A new box in **/admin → Screen → Privacy**, *Show the account + e-mail address*, off by default. Until you tick it, a widget that shows an account gets its plan + and how you signed in, never its e-mail address: the server does not send it, so no widget — + one from the marketplace included — can show it or pass it on. - **Claude sessions: go to the session.** Touch a card and its window comes forward — the exact Orca pane, the Terminal.app or iTerm2 tab, the VS Code window on that folder, or at least the application — for every session, hooked or merely found running. The card also says which application the session lives in, which is what tells two panes of the diff --git a/README.md b/README.md index d8e88269..fc477ec5 100644 --- a/README.md +++ b/README.md @@ -316,6 +316,12 @@ The list is short and it is all of it. | The Dock's badge counts and the icons of installed applications | the `notifications` and `shortcuts` widgets, through the helper | whenever one of those widgets is on the dashboard | | The volume, the battery, the disks, the processes, the network | those widgets, through `pmset`, `df`, `ps` and friends | whenever one of them is on the dashboard | +A widget that shows an account — its plan, how you signed in — never gets the account's e-mail +address unless you tick **/admin → Screen → Privacy → Show the account e-mail address**. It is off +by default, and the server leaves the address out of what it sends, so no widget can show it or +pass it on. Once on, every widget that reads that account's channel receives it, one installed +from the marketplace included, and it is on the screen. + Everything else Fremkit knows, you typed into it: the connections of the table above, whose secrets live in the macOS keychain (see [docs/connections.md](docs/connections.md)). Nothing is sent to any server other than the ones you configured, there is no telemetry, and the server diff --git a/docs/claude-code.md b/docs/claude-code.md index 8e373407..d7c3c604 100644 --- a/docs/claude-code.md +++ b/docs/claude-code.md @@ -93,3 +93,8 @@ macOS keychain (the item "Claude Code-credentials") every 5 minutes and calls th endpoint for per-model weekly limits. The token is never stored or logged and is sent only to `api.anthropic.com`. macOS may ask once to allow keychain access. The endpoint is undocumented and may change without notice. + +Nothing the Claude providers publish carries the account's e-mail address. Should one ever do so, +it is held to the rule every account provider is: the address is left out unless **/admin → +Screen → Privacy → Show the account e-mail address** is ticked (see +[connections.md](connections.md#the-accounts-e-mail-address)). diff --git a/docs/connections.md b/docs/connections.md index e9081b18..91da8111 100644 --- a/docs/connections.md +++ b/docs/connections.md @@ -78,6 +78,62 @@ are reduced to a phrase rather than passed through, because a network error can the URL can carry the organisation or the calendar address. Deleting a connection a widget still points at is refused with a 409 naming the widgets. +## The account's e-mail address + +A provider that signs in to an account — Claude, Codex, any service whose API answers with a +profile — **never publishes the account's e-mail address unless `privacy.showAccountEmail` is +on**, and it is off by default. The check belongs to the provider, on the server, not to the +widget: whatever lands on a channel reaches every widget subscribed to it, a third-party widget +from the marketplace with network access included, and that widget's consent dialog said "reads +channel X", not "reads your e-mail". A widget that hides the field has already received it. + +Build the snapshot with `withAccountEmail()` from `server/src/privacy.ts`, and read the setting +on every poll rather than once, so the admin's toggle takes effect without a restart: + +```ts +// server/src/app.ts +registry.register(createExampleAccountProvider({ + showAccountEmail: () => store.get().privacy.showAccountEmail, +})) // the provider object sets publishesAccountEmail: true + +// in the provider's poll() +return { plan: profile.plan, authMode, ...withAccountEmail(profile.email, opts.showAccountEmail()) } +``` + +Every snapshot the provider returns goes through `gateAccountEmail()` as well — the error path +above all. A provider that answers a failure with its last good snapshot would otherwise go on +publishing an address fetched while the box was ticked, after the user has unticked it: + +```ts +return gateAccountEmail({ ...last, error: 'offline' }, opts.showAccountEmail()) +``` + +`gateAccountEmail()` looks only at the top level of what it is given: apply it to **the object +that carries `email`**, on the fresh path, the error path and any stale answer alike. A snapshot +that holds the account under a key gates that object, not the snapshot around it: + +```ts +const show = opts.showAccountEmail() +return { + ...last, + error: 'offline', + account: { ...last.account, data: gateAccountEmail(last.account.data, show) }, +} +``` + +Set `publishesAccountEmail: true` on the provider. Toggling the setting then drops the hub's +cached value of its channel and polls it again at once instead of at its next tick, and an answer +from a poll that was already in flight is thrown away, since it may have read the old setting. +The address therefore leaves the screen when the box is unticked rather than five minutes later. +The flag needs a `poll()` — the registry refuses it otherwise — because a poll is the only way +anything reaches a channel. A provider whose endpoint is rate-limited should answer that extra poll from its last +snapshot, gated, rather than fetch again. + +Off, the snapshot has no `email` key at all — not an empty string, not a masked address. The plan +(Pro, Max, …) and the sign-in method are not covered by the setting and are published either way. +No provider built into Fremkit publishes an address today; this is the contract the first one is +held to. + ## Local Network macOS 15 and later gate LAN access per application. The server runs inside whatever launched it — diff --git a/server/src/app.ts b/server/src/app.ts index 8dc60424..d11c751d 100644 --- a/server/src/app.ts +++ b/server/src/app.ts @@ -201,8 +201,13 @@ export async function buildApp(opts: AppOptions): Promise { retainCameras(store.get()) hub.broadcast('config', store.get()) + let showAccountEmail = store.get().privacy.showAccountEmail store.onChange((cfg) => { setServerLocale(cfg.locale) + if (cfg.privacy.showAccountEmail !== showAccountEmail) { + showAccountEmail = cfg.privacy.showAccountEmail + registry.reconsiderAccountEmail() + } syncDeclared() hub.broadcast('config', cfg) // Fire and forget: a failed sync must not break the save that triggered it. diff --git a/server/src/config/migrate.ts b/server/src/config/migrate.ts index cfab3792..9701de6a 100644 --- a/server/src/config/migrate.ts +++ b/server/src/config/migrate.ts @@ -110,6 +110,9 @@ export function placesClaudeUsage(config: Config): boolean { * working, and an upgrade that silently blanked them would be a regression rather than a choice — * so that case starts enabled, and the admin's toggle is where it is turned back off. A config * that already carries the field is left exactly as written. + * + * `showAccountEmail` needs no such inference: no release ever published an account's e-mail, so + * an older config is read as off by the schema's default, which is what it always meant. */ function adoptPrivacy(config: Config, raw: unknown): Config { const stated = (raw as { privacy?: unknown } | null)?.privacy @@ -149,7 +152,7 @@ export function migrateConfig(raw: unknown): Config { connections: [], secrets: { backend: defaultSecretsBackend() }, locale: defaultLocale(), - privacy: { claudeAccountUsage: false }, + privacy: { claudeAccountUsage: false, showAccountEmail: false }, // A v1 config predates the marketplace by a long way; nothing can have been installed. marketplace: { installed: {} }, pages: v1.pages.map((p) => ({ diff --git a/server/src/config/schema.ts b/server/src/config/schema.ts index a41483d6..dbe62e5b 100644 --- a/server/src/config/schema.ts +++ b/server/src/config/schema.ts @@ -237,6 +237,14 @@ const PrivacySchema = z.object({ * undocumented and may disappear. */ claudeAccountUsage: z.boolean().default(false), + /** + * Let an account provider (Claude, Codex, …) put the account's e-mail address in what it + * publishes. Off, the field is never in the snapshot: anything on a channel reaches every + * widget subscribed to it, a third-party one with network access included, and the Edge sits + * on a desk. The plan and the sign-in method are published either way. Providers read it with + * `withAccountEmail()` from `privacy.ts` on every poll. + */ + showAccountEmail: z.boolean().default(false), }).prefault({}) /** @@ -341,7 +349,7 @@ export const DEFAULT_CONFIG: Config = { connections: [], secrets: { backend: defaultSecretsBackend() }, locale: defaultLocale(), - privacy: { claudeAccountUsage: false }, + privacy: { claudeAccountUsage: false, showAccountEmail: false }, marketplace: { installed: {} }, pages: [ { diff --git a/server/src/privacy.ts b/server/src/privacy.ts new file mode 100644 index 00000000..36d1d119 --- /dev/null +++ b/server/src/privacy.ts @@ -0,0 +1,35 @@ +/** + * The one way an account provider puts the account's e-mail address in a snapshot. + * + * Whatever a provider publishes reaches every widget subscribed to its channel — a third-party + * widget from the marketplace with network access included, whose consent dialog said "reads + * channel X", not "reads your e-mail" — and whatever a widget shows is on a screen on a desk. So + * the address is left out unless the user turned `privacy.showAccountEmail` on, and the check is + * made here, on the server, not by the widget that would display it. + * + * Spread the result into the snapshot: `{ plan, authMode, ...withAccountEmail(email, show()) }`. + * Pass `show` as `() => store.get().privacy.showAccountEmail` and call it on every poll rather + * than capturing it, so the admin's toggle takes effect without a restart. The plan and the + * sign-in method are not covered by the setting and are published either way. + */ +export function withAccountEmail(email: string | null | undefined, show: boolean): { email?: string } { + return show && email ? { email } : {} +} + +/** + * The same rule for a snapshot that already exists: the address is dropped unless `show` is on. + * + * A provider that answers a failure with its last good snapshot — `{ ...last, error }` — would + * otherwise go on publishing an address the user has hidden since it was fetched. So every + * snapshot a provider returns goes through this, the error path and a cached answer included: + * `return gateAccountEmail({ ...last, error: 'offline' }, opts.showAccountEmail())`. + * + * It looks at the top level of the object it is given, nothing deeper: apply it to the object + * that carries `email`. A snapshot holding the account under a key gates that object — + * `{ ...last, account: { ...last.account, data: gateAccountEmail(last.account.data, show) } }`. + */ +export function gateAccountEmail(snapshot: T, show: boolean): T { + if (show || !('email' in snapshot)) return snapshot + const { email: _email, ...rest } = snapshot as T & { email?: unknown } + return rest as T +} diff --git a/server/src/providers/registry.ts b/server/src/providers/registry.ts index feaadd5e..97ddd38b 100644 --- a/server/src/providers/registry.ts +++ b/server/src/providers/registry.ts @@ -21,6 +21,8 @@ interface State { backoffMs: number lastJson: string | undefined inFlight: boolean + /** Poll again as soon as the one in flight returns: it may have read a setting since changed. */ + pollAgain: boolean } export class ProviderRegistry { @@ -38,12 +40,17 @@ export class ProviderRegistry { ) {} register(provider: Provider): void { + // A poll is the only way anything reaches a channel, so a provider without one publishes no + // address and could never take one back: the flag there is a mistake, not a no-op. + if (provider.publishesAccountEmail && !provider.poll) { + throw new Error(`provider ${provider.channel}: publishesAccountEmail needs a poll()`) + } const previous = this.states.get(provider.channel) // Read before the teardown, which zeroes it: the widgets watching this channel did not go // away because the connection behind it was edited, so the replacement inherits them. const subscribers = previous?.subscribers ?? 0 if (previous) this.teardown(previous, 'gone') - const state: State = { provider, subscribers, started: false, timer: null, backoffMs: 0, lastJson: undefined, inFlight: false } + const state: State = { provider, subscribers, started: false, timer: null, backoffMs: 0, lastJson: undefined, inFlight: false, pollAgain: false } this.states.set(provider.channel, state) if (state.subscribers > 0) this.activate(state) } @@ -58,6 +65,26 @@ export class ProviderRegistry { channels(): string[] { return [...this.states.keys()] } + /** + * `privacy.showAccountEmail` changed: every provider that can publish the address answers again + * now, rather than at its next tick — five minutes for an account endpoint, during which an + * address the user has just hidden would stay on screen. + * + * The cached value goes first, watched or not, so the hub hands nothing stale to a widget that + * subscribes before the new answer arrives. A watched channel is then polled at once. A poll + * already in flight may have read the old setting, so its answer is thrown away when it returns + * — whether anyone is still watching or not — and the channel is polled again if someone is. + */ + reconsiderAccountEmail(): void { + for (const s of this.states.values()) { + if (!s.provider.publishesAccountEmail) continue + s.lastJson = undefined + this.forget(s.provider.channel) + if (s.inFlight) s.pollAgain = true + else if (s.subscribers > 0) this.schedule(s, 0) + } + } + has(channel: string): boolean { return this.states.has(channel) } addSubscriber(channel: string): void { @@ -162,6 +189,15 @@ export class ProviderRegistry { } // Checked again after the await, not only before it: this is where the replacement happens. if (!this.isCurrent(s)) return + if (s.pollAgain) { + // Computed under a privacy setting the user has changed since: never published. Forgotten + // again in case the channel went idle meanwhile, so nothing is cached for the next widget. + s.pollAgain = false + s.lastJson = undefined + this.forget(s.provider.channel) + if (s.subscribers > 0) this.schedule(s, 0) + return + } const json = JSON.stringify(data) if (json !== s.lastJson) { s.lastJson = json diff --git a/server/src/providers/types.ts b/server/src/providers/types.ts index 93d8e3b9..f3dc7718 100644 --- a/server/src/providers/types.ts +++ b/server/src/providers/types.ts @@ -22,5 +22,12 @@ export interface Provider { /** Called when the last subscriber leaves, and when the provider is unregistered. */ stop?(): void commands?: Record Promise> + /** + * Set by a provider whose snapshot can carry the account's e-mail address (see `privacy.ts`). + * Toggling `privacy.showAccountEmail` then polls it again at once, instead of leaving the old + * answer on screen until its next tick. Requires `poll`: the registry refuses the flag on a + * provider without one. + */ + publishesAccountEmail?: boolean } export type Publish = (channel: string, data: unknown) => void diff --git a/server/test/config-migration.test.ts b/server/test/config-migration.test.ts index 8a4d1926..c8aa32bb 100644 --- a/server/test/config-migration.test.ts +++ b/server/test/config-migration.test.ts @@ -145,6 +145,55 @@ describe('privacy.claudeAccountUsage on an older config', () => { }) }) +describe('privacy.showAccountEmail on an older config', () => { + const page = (widgets: object[]) => ({ id: 'home', name: 'Accueil', widgets }) + const widget = (widgetId: string) => ({ instanceId: 'a', widgetId, x: 0, y: 0, w: 8, h: 4 }) + + it('starts off for every config written before it existed', () => { + // Even next to the Claude opt-in being inferred on: reading the usage is not showing the e-mail. + const v3 = migrateConfig({ ...migrateConfig(v1), privacy: { claudeAccountUsage: true } }) + // toMatchObject: other privacy keys arrive in other branches and must not break this. + expect(v3.privacy).toMatchObject({ claudeAccountUsage: true, showAccountEmail: false }) + expect(migrateConfig({ version: 2, pages: [page([widget('claude-usage')])] }).privacy) + .toMatchObject({ claudeAccountUsage: true, showAccountEmail: false }) + expect(migrateConfig(v1).privacy.showAccountEmail).toBe(false) + }) + + it('respects the field once the file carries it', () => { + const v3 = (showAccountEmail: boolean) => migrateConfig({ + ...migrateConfig(v1), privacy: { claudeAccountUsage: false, showAccountEmail }, + }).privacy.showAccountEmail + expect(v3(true)).toBe(true) + expect(v3(false)).toBe(false) + }) + + it('leaves a v3 file without the field untouched on disk', async () => { + const dir = await mkdtemp(join(tmpdir(), 'fremkit-mig-')) + const file = join(dir, 'fremkit.json') + const { privacy: _privacy, ...rest } = migrateConfig(v1) + const before = JSON.stringify({ ...rest, privacy: { claudeAccountUsage: false } }, null, 2) + await writeFile(file, before) + const cfg = await new ConfigStore(file).load() + expect(cfg.privacy.showAccountEmail).toBe(false) + expect(await readFile(file, 'utf8')).toBe(before) + }) + + it('never rewrites a file whose value it cannot read', async () => { + const dir = await mkdtemp(join(tmpdir(), 'fremkit-mig-')) + const file = join(dir, 'fremkit.json') + const original = JSON.stringify({ ...migrateConfig(v1), privacy: { claudeAccountUsage: false, showAccountEmail: 'yes' } }) + await writeFile(file, original) + const err = vi.spyOn(console, 'error').mockImplementation(() => {}) + const store = new ConfigStore(file) + const cfg = await store.load() + err.mockRestore() + expect(store.degraded).toBe(true) + expect(cfg.privacy.showAccountEmail).toBe(false) + expect(await readFile(file, 'utf8')).toBe(original) + expect(await readdir(dir)).toEqual(['fremkit.json']) + }) +}) + describe('renamed stored values', () => { const withModel = (model: string) => ({ version: 2, diff --git a/server/test/privacy.test.ts b/server/test/privacy.test.ts new file mode 100644 index 00000000..f5a2b37e --- /dev/null +++ b/server/test/privacy.test.ts @@ -0,0 +1,62 @@ +import { describe, it, expect } from 'vitest' +import { gateAccountEmail, withAccountEmail } from '../src/privacy.js' +import { ConfigSchema, DEFAULT_CONFIG } from '../src/config/schema.js' + +describe('withAccountEmail', () => { + const snapshot = (show: boolean) => ({ plan: 'max', authMode: 'oauth', ...withAccountEmail('someone@example.com', show) }) + + it('leaves the address out of the snapshot when the setting is off', () => { + const s = snapshot(false) + expect(s).not.toHaveProperty('email') + // Not an empty or masked value either: the key is absent, so nothing reaches a widget. + expect(JSON.stringify(s)).not.toContain('example.com') + }) + + it('keeps the plan and the sign-in method whatever the setting', () => { + expect(snapshot(false)).toEqual({ plan: 'max', authMode: 'oauth' }) + expect(snapshot(true)).toEqual({ plan: 'max', authMode: 'oauth', email: 'someone@example.com' }) + }) + + it('publishes nothing when there is no address to publish', () => { + expect(withAccountEmail(null, true)).toEqual({}) + expect(withAccountEmail(undefined, true)).toEqual({}) + expect(withAccountEmail('', true)).toEqual({}) + }) + + it('is off on a fresh install', () => { + expect(DEFAULT_CONFIG.privacy.showAccountEmail).toBe(false) + expect(ConfigSchema.shape.privacy.parse(undefined).showAccountEmail).toBe(false) + }) +}) + +describe('gateAccountEmail', () => { + const last = { plan: 'max', authMode: 'oauth', email: 'someone@example.com' } + + it('drops an address already in a cached snapshot once the setting is off', () => { + // The error path: the last good snapshot, fetched while the box was ticked, republished. + const s = gateAccountEmail({ ...last, error: 'offline' }, false) + expect(s).toEqual({ plan: 'max', authMode: 'oauth', error: 'offline' }) + expect(s).not.toHaveProperty('email') + }) + + it('gates a nested account on the object that carries the address', () => { + // The shape of a snapshot that holds the account under a key, republished on failure. + const stale = { account: { status: 'ok', data: { plan: 'pro', email: 'someone@example.com' } }, history: [] } + const gated = (show: boolean) => ({ + ...stale, + error: 'offline', + account: { ...stale.account, data: gateAccountEmail(stale.account.data, show) }, + }) + expect(gated(false)).toEqual({ account: { status: 'ok', data: { plan: 'pro' } }, history: [], error: 'offline' }) + expect(JSON.stringify(gated(false))).not.toContain('example.com') + expect(gated(true).account.data.email).toBe('someone@example.com') + // Applied to the outer snapshot instead it changes nothing, which is why the docs say where. + expect(JSON.stringify(gateAccountEmail(stale, false))).toContain('example.com') + }) + + it('keeps it while the setting is on, and leaves a snapshot without one alone', () => { + expect(gateAccountEmail(last, true)).toBe(last) + const plain = { plan: 'pro' } + expect(gateAccountEmail(plain, false)).toBe(plain) + }) +}) diff --git a/server/test/provider-registry.test.ts b/server/test/provider-registry.test.ts index b14515f5..55e3167a 100644 --- a/server/test/provider-registry.test.ts +++ b/server/test/provider-registry.test.ts @@ -283,3 +283,118 @@ describe('runCommand and the prototype chain', () => { await expect(registry.runCommand('ghost', 'real', null)).rejects.toThrow(/canal inconnu/) }) }) + +describe('ProviderRegistry.reconsiderAccountEmail', () => { + // Stands in for an account provider: what it publishes depends on the setting at poll time. + function account(show: { on: boolean }, intervalMs = 300_000) { + let polls = 0 + let release: (() => void) | null = null + const provider: Provider = { + channel: 'account', intervalMs, publishesAccountEmail: true, + async poll() { + polls++ + const seen = show.on + if (hold.on) await new Promise((r) => { release = r }) + return seen ? { plan: 'max', email: 'someone@example.com' } : { plan: 'max' } + }, + } + const hold = { on: false } + return { provider, polls: () => polls, hold, release: () => release?.() } + } + + it('polls a watched provider at once instead of at its next tick', async () => { + const publish = vi.fn() + const show = { on: true } + const a = account(show) + const reg = new ProviderRegistry(publish) + reg.register(a.provider) + reg.addSubscriber('account') + await vi.advanceTimersByTimeAsync(0) + expect(publish).toHaveBeenLastCalledWith('account', { plan: 'max', email: 'someone@example.com' }) + show.on = false + reg.reconsiderAccountEmail() + await vi.advanceTimersByTimeAsync(0) + expect(a.polls()).toBe(2) + expect(publish).toHaveBeenLastCalledWith('account', { plan: 'max' }) + reg.stop() + }) + + it('throws away a poll in flight that read the old setting, and polls again', async () => { + const publish = vi.fn() + const show = { on: true } + const a = account(show) + const reg = new ProviderRegistry(publish) + reg.register(a.provider) + a.hold.on = true + reg.addSubscriber('account') + await vi.advanceTimersByTimeAsync(0) + show.on = false + reg.reconsiderAccountEmail() + a.hold.on = false + a.release() + await vi.advanceTimersByTimeAsync(0) + expect(a.polls()).toBe(2) + // The first answer carried the address and was read before the change: never published. + expect(publish).toHaveBeenCalledTimes(1) + expect(publish).toHaveBeenCalledWith('account', { plan: 'max' }) + reg.stop() + }) + + it('drops the cache of a watched channel before the new answer arrives', async () => { + const forget = vi.fn() + const show = { on: true } + const a = account(show) + const reg = new ProviderRegistry(vi.fn(), forget) + reg.register(a.provider) + reg.addSubscriber('account') + await vi.advanceTimersByTimeAsync(0) + show.on = false + reg.reconsiderAccountEmail() + // Synchronously: a widget subscribing in the meantime must not be replayed the address. + expect(forget).toHaveBeenCalledWith('account') + reg.stop() + }) + + it('neither publishes nor caches a poll in flight when the last widget left meanwhile', async () => { + const publish = vi.fn() + const forget = vi.fn() + const show = { on: true } + const a = account(show) + const reg = new ProviderRegistry(publish, forget) + reg.register(a.provider) + a.hold.on = true + reg.addSubscriber('account') + await vi.advanceTimersByTimeAsync(0) + reg.removeSubscriber('account') + show.on = false + reg.reconsiderAccountEmail() + forget.mockClear() + a.release() + await vi.advanceTimersByTimeAsync(0) + expect(publish).not.toHaveBeenCalled() + expect(forget).toHaveBeenCalledWith('account') + expect(a.polls()).toBe(1) + reg.stop() + }) + + it('refuses the flag on a provider with no poll', () => { + const reg = new ProviderRegistry(vi.fn()) + expect(() => reg.register({ channel: 'push', publishesAccountEmail: true })).toThrow(/needs a poll/) + }) + + it('drops the cached value of a channel nobody watches, and leaves other providers alone', async () => { + const forget = vi.fn() + const reg = new ProviderRegistry(vi.fn(), forget) + reg.register(account({ on: true }).provider) + const other = make([1]) + reg.register(other.provider) + reg.addSubscriber('test') + await vi.advanceTimersByTimeAsync(0) + reg.reconsiderAccountEmail() + await vi.advanceTimersByTimeAsync(0) + expect(forget).toHaveBeenCalledWith('account') + expect(forget).not.toHaveBeenCalledWith('test') + expect(other.polls()).toBe(1) + reg.stop() + }) +}) diff --git a/ui/src/admin/ScreenInspector.vue b/ui/src/admin/ScreenInspector.vue index 91ccae6c..89b34efa 100644 --- a/ui/src/admin/ScreenInspector.vue +++ b/ui/src/admin/ScreenInspector.vue @@ -62,6 +62,13 @@ const privacy = computed(() => s.state.config!.privacy) function setClaudeAccountUsage(on: boolean): void { s.apply((c) => { c.privacy.claudeAccountUsage = on }) } +/** + * Off, the server leaves the account e-mail out of every snapshot it publishes; this box does + * not hide it in a widget, it decides whether any widget is sent it at all. + */ +function setShowAccountEmail(on: boolean): void { + s.apply((c) => { c.privacy.showAccountEmail = on }) +} /** * Backup and restore. * @@ -263,6 +270,10 @@ function setBackground(patch: Partial): void { :label="t('admin.inspector.screen.claudeUsage')" @update:model-value="setClaudeAccountUsage($event)" />

{{ t('admin.inspector.screen.claudeUsage.hint') }}

+ +

{{ t('admin.inspector.screen.accountEmail.hint') }}

diff --git a/ui/src/shared/locales/en.ts b/ui/src/shared/locales/en.ts index e385747e..276650ac 100644 --- a/ui/src/shared/locales/en.ts +++ b/ui/src/shared/locales/en.ts @@ -184,6 +184,8 @@ export const en: Record = { 'admin.inspector.screen.privacy': 'Privacy', 'admin.inspector.screen.claudeUsage': 'Read the Claude account usage', 'admin.inspector.screen.claudeUsage.hint': 'Off for a new install. A dashboard that already showed the Claude widget before this setting existed keeps it on, so the gauges do not go blank on an upgrade. Once on, the server reads Claude Code’s OAuth token from the “Claude Code-credentials” keychain item and presents it to api.anthropic.com to get the account’s usage — nothing is sent anywhere else, and the token is never stored or logged. The endpoint is not documented by Anthropic and may disappear.', + 'admin.inspector.screen.accountEmail': 'Show the account e-mail address', + 'admin.inspector.screen.accountEmail.hint': 'Off by default. Widgets that show an account then get the plan and the sign-in method, never the e-mail address: the server leaves it out of what it sends. Once on, the address is sent to every widget that reads an account channel — a widget installed from the marketplace included — and appears on the screen.', 'admin.inspector.screen.navWidgets': 'Navigation bar widgets', 'admin.inspector.screen.navWidgets.hint': 'Drawn on either side of the dots, in this order.', 'admin.inspector.screen.navWidgets.slot.left': 'Left', diff --git a/ui/src/shared/locales/fr.ts b/ui/src/shared/locales/fr.ts index 5f2f9e7b..1672a907 100644 --- a/ui/src/shared/locales/fr.ts +++ b/ui/src/shared/locales/fr.ts @@ -184,6 +184,8 @@ export const fr: Record = { 'admin.inspector.screen.privacy': 'Confidentialité', 'admin.inspector.screen.claudeUsage': 'Lire la consommation du compte Claude', 'admin.inspector.screen.claudeUsage.hint': 'Désactivé pour une nouvelle installation. Un tableau de bord qui affichait déjà le widget Claude avant l’existence de ce réglage le conserve activé, pour que les jauges ne se vident pas lors d’une mise à jour. Une fois activé, le serveur lit le jeton OAuth de Claude Code dans l’élément de trousseau « Claude Code-credentials » et le présente à api.anthropic.com pour obtenir la consommation du compte — rien n’est envoyé ailleurs, et le jeton n’est ni enregistré ni journalisé. Le point d’accès n’est pas documenté par Anthropic et peut disparaître.', + 'admin.inspector.screen.accountEmail': 'Afficher l’adresse e-mail du compte', + 'admin.inspector.screen.accountEmail.hint': 'Désactivé par défaut. Les widgets qui affichent un compte reçoivent alors le forfait et le mode de connexion, jamais l’adresse e-mail : le serveur la retire de ce qu’il envoie. Une fois activé, l’adresse est envoyée à chaque widget qui lit un canal de compte — y compris un widget installé depuis la marketplace — et apparaît à l’écran.', 'admin.inspector.screen.navWidgets': 'Widgets de la barre', 'admin.inspector.screen.navWidgets.hint': 'Répartis de part et d’autre des pastilles, dans cet ordre.', 'admin.inspector.screen.navWidgets.slot.left': 'Gauche', diff --git a/ui/src/shared/types.ts b/ui/src/shared/types.ts index ca2fdb3f..2d36da93 100644 --- a/ui/src/shared/types.ts +++ b/ui/src/shared/types.ts @@ -75,6 +75,11 @@ export interface Privacy { * usage — the gauges of the claude-usage widget. */ claudeAccountUsage: boolean + /** + * Let account providers publish the account's e-mail address. Off, the server leaves it out + * of every snapshot, so no widget and no screen ever sees it. + */ + showAccountEmail: boolean } export interface Config { diff --git a/ui/test/marketplace-modal.test.ts b/ui/test/marketplace-modal.test.ts index 8608af90..1fd0d03e 100644 --- a/ui/test/marketplace-modal.test.ts +++ b/ui/test/marketplace-modal.test.ts @@ -59,7 +59,7 @@ function config(): Config { version: 3, display: { cols: 64, rows: 16, cell: 40, autoCycleSeconds: 0 }, connections: [], secrets: { backend: 'file' }, locale: 'en', - privacy: { claudeAccountUsage: false }, marketplace: { installed: {} }, + privacy: { claudeAccountUsage: false, showAccountEmail: false }, marketplace: { installed: {} }, pages: [{ id: 'home', name: 'Home', widgets: [] }], } as unknown as Config } diff --git a/ui/test/permissions-asks.test.ts b/ui/test/permissions-asks.test.ts index 6cecf561..c9d63883 100644 --- a/ui/test/permissions-asks.test.ts +++ b/ui/test/permissions-asks.test.ts @@ -41,7 +41,7 @@ function config(): Config { version: 3, display: { cols: 64, rows: 16, cell: 40, autoCycleSeconds: 0 }, connections: [], secrets: { backend: 'file' }, locale: 'en', - privacy: { claudeAccountUsage: false }, + privacy: { claudeAccountUsage: false, showAccountEmail: false }, marketplace: { installed: {} }, pages: [{ id: 'home', name: 'Home', diff --git a/ui/test/store.test.ts b/ui/test/store.test.ts index 8f38f6ff..f9f57f76 100644 --- a/ui/test/store.test.ts +++ b/ui/test/store.test.ts @@ -28,7 +28,7 @@ function config(): Config { display: { cols: 64, rows: 16, cell: 40, autoCycleSeconds: 0 }, connections: [], secrets: { backend: 'file' }, - privacy: { claudeAccountUsage: false }, + privacy: { claudeAccountUsage: false, showAccountEmail: false }, pages: [{ id: 'home', name: 'Accueil', widgets: [ { instanceId: 'clock-1', widgetId: 'clock', x: 0, y: 0, w: 16, h: 4, showTitle: true, settings: {} }, ] }], diff --git a/ui/test/theme-repaint.test.ts b/ui/test/theme-repaint.test.ts index 05ba2099..9396b530 100644 --- a/ui/test/theme-repaint.test.ts +++ b/ui/test/theme-repaint.test.ts @@ -18,7 +18,7 @@ function config(theme: string): Config { version: 3, display: { cols: 64, rows: 16, cell: 40, autoCycleSeconds: 0, theme }, connections: [], secrets: { backend: 'file' }, locale: 'en', - privacy: { claudeAccountUsage: false }, marketplace: { installed: {} }, + privacy: { claudeAccountUsage: false, showAccountEmail: false }, marketplace: { installed: {} }, pages: [{ id: 'home', name: 'Home', widgets: [] }], } as unknown as Config }