fix: never greet the user by the assistant's default name (UF-055)

Home and the sidebar read the user's name from the identity row, which the
sidecar fills with the assistant's identity named Waggle. Both now use the
profile name, with the identity name as a fallback that skips the default.
This commit is contained in:
shumeiko.it
2026-10-27 14:24:35 +01:00
parent c2998f1a6b
commit 659c84bee2
8 changed files with 111 additions and 13 deletions

View File

@@ -24,6 +24,7 @@ import RouteTransition from './RouteTransition';
import Sidebar, { type SidebarNavItem } from './Sidebar';
import AppErrorBoundary from './ErrorBoundary';
import { adapter } from '@/lib/adapter';
import { pickUserName } from '@/lib/user-name';
import { stashDeepLink } from '@/lib/app-deeplink';
import { writeLoginBriefingDismissed, writeLoginBriefingLastDismissedAt, readLoginBriefingDismissed, readSkipBriefingParam } from '@/lib/login-briefing';
import { prefetchBriefing, computeAwayDays, BRIEFING_ABSENCE_DAYS } from '@/lib/briefing-source';
@@ -198,10 +199,17 @@ const ShellLayout = () => {
const [userName, setUserName] = useState<string | null>(null);
useEffect(() => {
let cancelled = false;
// The user's name comes from their profile; the identity row is a fallback
// that may hold the assistant's default name (UF-055). Neither set: the row
// degrades to "Account".
const loadIdentity = () => {
adapter.getIdentity()
.then(r => { if (!cancelled) setUserName(r.name ?? null); })
.catch(() => { /* identity is optional — the row degrades to "Account" */ });
const read = <T,>(fn: () => Promise<T>) => Promise.resolve().then(fn).catch(() => null);
void Promise.all([read(() => adapter.getProfile()), read(() => adapter.getIdentity())])
.then(([profile, identity]) => {
if (cancelled) return;
const profileName = typeof profile?.name === 'string' ? profile.name : null;
setUserName(pickUserName(profileName, identity?.name));
});
};
loadIdentity();
window.addEventListener('waggle:connect-settled', loadIdentity);

View File

@@ -0,0 +1,18 @@
import { describe, it, expect } from 'vitest';
import { pickUserName } from './user-name';
describe('pickUserName (UF-055)', () => {
it('prefers the name in the profile', () => {
expect(pickUserName('Ana', 'Waggle')).toBe('Ana');
expect(pickUserName(' Ana ', 'Marko')).toBe('Ana');
});
it('falls back to a real identity name', () => {
expect(pickUserName('', 'Marko')).toBe('Marko');
});
it('never returns the assistant default name as the user', () => {
expect(pickUserName(null, 'Waggle')).toBeNull();
expect(pickUserName(undefined, undefined)).toBeNull();
});
});

View File

@@ -0,0 +1,13 @@
/** The assistant's default identity name (DEFAULT_AGENT_NAME in @waggle/agent). */
export const ASSISTANT_DEFAULT_NAME = 'Waggle';
/**
* The user's display name: the one in their profile, else the identity row's
* name unless that is the assistant's default (UF-055). Null means unknown.
*/
export function pickUserName(profileName?: string | null, identityName?: string | null): string | null {
const fromProfile = profileName?.trim();
if (fromProfile) return fromProfile;
const fromIdentity = identityName?.trim();
return fromIdentity && fromIdentity !== ASSISTANT_DEFAULT_NAME ? fromIdentity : null;
}