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

@@ -7,8 +7,11 @@ export interface IdentityConfig {
capabilities?: string[];
}
/** The assistant's own default name. It is not the user's name. */
export const DEFAULT_AGENT_NAME = 'Waggle';
const DEFAULT_IDENTITY: Required<IdentityConfig> = {
name: 'Waggle',
name: DEFAULT_AGENT_NAME,
role: 'AI assistant with persistent memory and web access',
personality:
'Direct, concise, helpful. Leads with answers, avoids filler. Admits uncertainty rather than guessing.',

View File

@@ -198,7 +198,7 @@ export {
type MessagesCompressionEvent,
type CompressMessagesResult,
} from './long-task/messages-compressor.js';
export { ensureIdentity, type IdentityConfig } from './auto-identity.js';
export { ensureIdentity, DEFAULT_AGENT_NAME, type IdentityConfig } from './auto-identity.js';
export { buildSelfAwareness, type AgentCapabilities } from './self-awareness.js';
export {
loadSystemPrompt,

View File

@@ -26,6 +26,7 @@
import type { FastifyPluginAsync } from 'fastify';
import { IdentityLayer } from '@waggle/core';
import { DEFAULT_AGENT_NAME } from '@waggle/agent';
import { PERSONAL_SCOPE } from '@waggle/memory-contract';
import { memoryStatus } from '../memory-status.js';
import { buildWorkspaceState } from '../workspace-state.js';
@@ -35,6 +36,7 @@ import {
type CronScheduleLike,
} from './workspace-context.js';
import { getAuditDb } from './events.js';
import { loadProfile } from './profile.js';
import { createLogger } from '../logger.js';
const log = createLogger('home');
@@ -256,16 +258,27 @@ export const homeRoutes: FastifyPluginAsync = async (server) => {
server.get('/api/home/briefing', async () => {
const now = new Date();
// ── Greeting + identity name (B8) ─────────────────────────────
// ── Greeting + user name (B8) ─────────────────────────────
// The user's name comes from profile.json, which the user states. The
// identity row is only a fallback: it also holds the assistant's identity,
// whose default name is the product's, so a user who skipped their name
// was greeted "Welcome, Waggle" (UF-055).
let userName: string | undefined;
try {
const layer = new IdentityLayer(server.waggleDb);
if (layer.exists()) {
const name = layer.get().name?.trim();
if (name) userName = name;
const dataDir = server.localConfig?.dataDir;
if (dataDir) {
const profileName = loadProfile(dataDir).name?.trim();
if (profileName) userName = profileName;
}
if (!userName) {
try {
const layer = new IdentityLayer(server.waggleDb);
if (layer.exists()) {
const name = layer.get().name?.trim();
if (name && name !== DEFAULT_AGENT_NAME) userName = name;
}
} catch (err) {
log.warn('briefing: identity read failed', (err as Error).message);
}
} catch (err) {
log.warn('briefing: identity read failed', (err as Error).message);
}
const ranked = rankPersonalWorkspaces();

View File

@@ -17,6 +17,9 @@
* emitAuditEvent stays a safe no-op.
*/
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import Fastify from 'fastify';
import { IdentityLayer, WaggleDB } from '@waggle/core';
@@ -193,6 +196,36 @@ describe('GET /api/home/briefing (P2 — J08 needsReviewCount + greeting)', () =
expect(res.json().userName).toBeUndefined();
expect(res.json().greeting).not.toContain(',');
});
function seedAssistantIdentity() {
new IdentityLayer(server.waggleDb).create({
name: 'Waggle', role: 'AI assistant with persistent memory and web access', department: '',
personality: '', capabilities: '', system_prompt: '',
});
}
it('UF-055: never greets the user by the assistant\'s default name', async () => {
boot();
seedAssistantIdentity();
const res = await server.inject({ method: 'GET', url: '/api/home/briefing' });
expect(res.json().userName).toBeUndefined();
expect(res.json().greeting).not.toContain('Waggle');
});
it('UF-055: greets by the name the user gave in their profile', async () => {
const dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'waggle-home-profile-'));
try {
fs.writeFileSync(path.join(dataDir, 'profile.json'), JSON.stringify({ name: 'Ana' }));
boot();
server.decorate('localConfig', { dataDir } as never);
seedAssistantIdentity();
const res = await server.inject({ method: 'GET', url: '/api/home/briefing' });
expect(res.json().userName).toBe('Ana');
expect(res.json().greeting).toContain(', Ana');
} finally {
fs.rmSync(dataDir, { recursive: true, force: true });
}
});
});
describe('upNext schedule aggregation (global jobs dedup + future-only)', () => {